dxf->writeHatch, but how ?

Use this forum to ask questions about how to do things in dxflib.

Moderator: andrew

dxf->writeHatch, but how ?

Postby bonsalty » Wed Jun 10, 2009 10:12 am

I havent found how to write a hatch into dxf

We have:
void DL_Dxf::writeHatch1 ( DL_WriterA & dw,
const DL_HatchData & data,
const DL_Attributes & attrib
)
where DL_HatchData (int hNumLoops, bool hSolid, double hScale, double hAngle, const string &hPattern)

First question: what shoud hPattern be and whats this hNumLoops all about?
Second question:

If I call :
void DL_Dxf::writeHatchLoop1 ( DL_WriterA & dw,
const DL_HatchLoopData & data
)
should I call the writeHatchEdge functions after this or before the writeHatchLoop?

Third question,why must I call writeHatch2 and how to use it ????

An example would be nice,since its impossible to decode it from the ribbonsofts class reference. Thank you!
bonsalty
Newbie Member
 
Posts: 9
Joined: Tue Jun 09, 2009 2:54 pm

Postby andrew » Wed Jun 10, 2009 2:11 pm

User avatar
andrew
Site Admin
 
Posts: 2661
Joined: Fri Mar 30, 2007 6:07 am

works, but not everything...

Postby bonsalty » Wed Jun 10, 2009 7:27 pm

Thanks I managed to use it. I inserted a single loop with 3 edges(a triangle :) ) and succeded to make a triangle with hatch.

But pattern name is still a mistery.
I tried "EARTH", "ANSI31",... default pattern names,but nothing happens. However I can see that names in autocad when I click on my hatchobject, but it doesnt change the hatch style?!
I tried rotate and scale property too,they doesnt work either. Its always a 45 degree hatch.The solid property works fine.
bonsalty
Newbie Member
 
Posts: 9
Joined: Tue Jun 09, 2009 2:54 pm

Re: dxf->writeHatch, but how ?

Postby wolfhergang » Thu Nov 07, 2013 11:14 pm

Im having some troubles in writing a solid arc hatch, i wrote a single hatch, with a single loop with a single edge all of em with the same attributes and it just doesnt work, any advice?
wolfhergang
Junior Member
 
Posts: 11
Joined: Tue Oct 08, 2013 11:55 pm

Re: dxf->writeHatch, but how ?

Postby wolfhergang » Thu Nov 14, 2013 12:56 am

Anyone?
wolfhergang
Junior Member
 
Posts: 11
Joined: Tue Oct 08, 2013 11:55 pm

Re: dxf->writeHatch, but how ?

Postby andrew » Thu Nov 14, 2013 2:01 pm

wolfhergang: Can you post your code or the exact example data?
I don't see how a hatch with one loop which contains one arc can form a closed, hatchable contour (unless the arc is in fact a full circle?).
User avatar
andrew
Site Admin
 
Posts: 2661
Joined: Fri Mar 30, 2007 6:07 am

Re: dxf->writeHatch, but how ?

Postby wolfhergang » Fri Nov 15, 2013 12:17 am

My code is this:

DxfExporter exportador("testingWriting.dxf");
exportador.addEntity(new DxfCircle(0,0,0,100,DL_Attributes()));
DL_Attributes generalAttrib = DL_Attributes("0",2,16776960, -1, "BYLAYER");
exportador.addEntity((new DxfHatch(1,true,1,0,"SOLID",generalAttrib)));
exportador.addEntity(new DxfHatchLoop(1,generalAttrib));
exportador.addEntity(new DxfHatchEdge(0,0,100,0,6.75,true,generalAttrib));

if(exportador.writeToDxfFile()){
std::cout<<"File wrote correctly"<<std::endl;
}else{
std::cout<<"Error at writing"<<std::endl;
}

in my implementation you "add" the entities to a container then you write the container to the file.
the entity constructors are basically the same as the DL_Entity ones, but mine store the attributes, thats it.

the arc is supposed to be a full circle from 0 to 6.74 degrees but it doesnt render.

pd: sorry about my english, if something doesnt make sense let me know and ill try to explain myself.
wolfhergang
Junior Member
 
Posts: 11
Joined: Tue Oct 08, 2013 11:55 pm

Re: dxf->writeHatch, but how ?

Postby wolfhergang » Fri Nov 15, 2013 12:22 am

Maybe im just confused about how im supposed to hatch things....
wolfhergang
Junior Member
 
Posts: 11
Joined: Tue Oct 08, 2013 11:55 pm

Re: dxf->writeHatch, but how ?

Postby andrew » Fri Nov 15, 2013 2:13 pm

wolfhergang: this code does not look familiar to me. dxflib does not provide the classes named "DxfExporter", "DxfHatch", "DxfCircle", etc.

Here's a minimal but complete example that writes a DXF file with one hatch entity using dxflib 3.3.4:

#include "dl_dxf.h"

int main() {
DL_Dxf dxf;
DL_WriterA* dw = dxf.out("hatch.dxf", DL_Codes::AC1015);

// section header:
dxf.writeHeader(*dw);
dw->sectionEnd();

// section tables:
{
dw->sectionTables();

// VPORT:
dxf.writeVPort(*dw);

// LTYPE:
dw->tableLineTypes(1);
dxf.writeLineType(*dw, DL_LineTypeData("CONTINUOUS", 0));
dw->tableEnd();

// LAYER:
dw->tableLayers(1);
dxf.writeLayer(
*dw,
DL_LayerData("0", 0),
DL_Attributes("", 2, 0, 100, "CONTINUOUS")
);
dw->tableEnd();

// STYLE:
dw->tableStyle(1);
DL_StyleData style("Standard", 0, 0.0, 1.0, 0.0, 0, 2.5, "txt", "");
style.bold = false;
style.italic = false;
dxf.writeStyle(*dw, style);
dw->tableEnd();

// VIEW:
dxf.writeView(*dw);

// UCS:
dxf.writeUcs(*dw);

// APPID:
dw->tableAppid(1);
dxf.writeAppid(*dw, "ACAD");
dw->tableEnd();

// DIMSTYLE:
dxf.writeDimStyle(*dw, 2.5, 0.625, 0.625, 0.625, 2.5);

// BLOCK_RECORD:
dxf.writeBlockRecord(*dw);
dw->tableEnd();

dw->sectionEnd();
}

// BLOCK:
dw->sectionBlocks();
dxf.writeBlock(*dw, DL_BlockData("*Model_Space", 0, 0.0, 0.0, 0.0));
dxf.writeEndBlock(*dw, "*Model_Space");
dw->sectionEnd();

// ENTITIES:
dw->sectionEntities();

DL_Attributes attributes("0", 2, 0, -1, "BYLAYER");

// start hatch with one loop:
DL_HatchData data(1, false, 1.0, 0.0, "ESCHER", 0.0, 0.0);
dxf.writeHatch1(*dw, data, attributes);

// start loop:
DL_HatchLoopData lData(1);
dxf.writeHatchLoop1(*dw, lData);

// write edge:
DL_HatchEdgeData eData(
0.0,
0.0,
100.0,
0.0,
M_PI*2,
true
);
dxf.writeHatchEdge(*dw, eData);

// end loop:
dxf.writeHatchLoop2(*dw, lData);

// end hatch:
dxf.writeHatch2(*dw, data, attributes);

// end section ENTITIES:
dw->sectionEnd();

dw->dxfEOF();
dw->close();
delete dw;

return 0;
}
User avatar
andrew
Site Admin
 
Posts: 2661
Joined: Fri Mar 30, 2007 6:07 am

Re: dxf->writeHatch, but how ?

Postby wolfhergang » Fri Nov 15, 2013 11:51 pm

My problem was that i was writing the hatch edge using degrees when im supposed to use radians.

DL_HatchEdgeData eData(0.0, 0.0, 100.0, 0.0, M_PI*2, true);

that single line solved my problem, than you very much Andrew.
wolfhergang
Junior Member
 
Posts: 11
Joined: Tue Oct 08, 2013 11:55 pm


Return to dxflib 'How Do I' Questions

Who is online

Users browsing this forum: No registered users and 2 guests