C++读取和⽣成dxf⽂件(⼆)
上次我们说到怎么通过C++读取dxf⽂件,这次我们继续来讲怎么通过C++(写)⽣成dxf⽂件。
⼀开始,与以前⼀样,⽣成dxf⽂件需要⽤到dxflib库,具体怎么获取dxflib库和怎么加载,可以参考以前我写的C++读取dxf⽂件(⼀)的开始部分。
DL_Dxf dxf;
DL_WriterA*dw=dxf.out("C:/dxf/demo.dxf",DL_Codes::AC1015);
//section header:
dxf.writeHeader(*dw);
dw->sectionEnd();
//section tables:
dw->sectionTables();
//VPORT:
dxf.writeVPort(*dw);
//LTYPE:
dw->tableLinetypes(1);dxf文件怎么打开
dxf.writeLinetype(*dw,DL_LinetypeData("CONTINUOUS","Continuous",0,0,0.0));
dxf.writeLinetype(*dw,DL_LinetypeData("BYLAYER","",0,0,0.0));
dxf.writeLinetype(*dw,DL_LinetypeData("BYBLOCK","",0,0,0.0));
dw->tableEnd();
//LAYER:
dw->tableLayers(1);
dxf.writeLayer(
*dw,
DL_LayerData("0",0),
DL_Attributes("",1,0x00ff0000,15,"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");
dxf.writeBlock(*dw,DL_BlockData("*Paper_Space",0,0.0,0.0,0.0)); dxf.writeEndBlock(*dw,"*Paper_Space");
dxf.writeBlock(*dw,DL_BlockData("*Paper_Space0",0,0.0,0.0,0.0)); dxf.writeEndBlock(*dw,"*Paper_Space0");
dw->sectionEnd();
//ENTITIES:
dw->sectionEntities();
DL_Attributes attributes("0",256,0x00ffff00,5,"BYLAYER");
//LINE:
DL_LineData lineData(10,5,0,30,5,0);
dxf.writeLine(*dw,lineData,attributes);
//CIRCLE
DL_CircleData circleData(10,10,0,4);
dxf.writeCircle(*dw,circleData,attributes);
//end section ENTITIES:
dw->sectionEnd();
dxf.writeObjects(*dw,"MY_OBJECTS");
dxf.writeObjectsEnd(*dw);
dw->dxfEOF();
dw->close();
delete dw;
我们可以通过下⾯这句话
DL_Attributes attributes("0",256,0x00ffff00,5,"BYLAYER");
来修改dxf图形的线条颜⾊、粗细、类型,其函数原型如下:/**
*Constructor for DXF attributes.
*
*@param layer Layer name for this entity or NULL for no layer *(every entity should be on a named layer!).
*@param color Color number(0..256).0=BYBLOCK,256=BYLAYER.
*@param color2424bit color(0x00RRGGBB,see DXF reference).
*@param width Line thickness.Defaults to zero.-1=BYLAYER,
*-2=BYBLOCK,-3=default width
*@param linetype Line type name or"BYLAYER"or"BYBLOCK".Defaults *to"BYLAYER"
*/
DL_Attributes(const std::string&layer,
int color,int color24,int width,
const std::string&linetype,
int handle=-1):
layer(layer),
color(color),
color24(color24),
width(width),
linetype(linetype),
linetypeScale(1.0),
handle(handle),
inPaperSpace(false){
}
在这⾥我画了两个元素上去(直线和圆)
//LINE:
DL_LineData lineData(10,5,0,30,5,0);
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论