|
本帖最后由 skny2011 于 2019-6-20 15:41 编辑
原创分享】分享一个读取DXF文件中多边形的源代码,有需要可以看看。
话不多说,上代码:
代码中有简单的注释,有不懂的大家可以留言讨论。
DXF文件格式请参考:http://docs.autodesk.com/ACD/201 ... 00849a0ab7-5f35.htm
defstruct(VertexStruct x y c)
defstruct(LineStruct str_x str_y end_x end_y)
defstruct(CircleStruct x y r)
axlCmdRegister("rdxf" 'ReadDXF)
defun( ReadDXF ()
let( (LineStart_x LineStart_y LineEnd_x LineEnd_y LineStart LineEnd)
if(isFile("./TemplateDXF.dxf") then
myDxf= infile("./TemplateDXF.dxf")
Start_Flag=nil
End_Flag=nil
while(!End_Flag
firstTime=t
fscanf(myDxf "%s\n" Temp)
LineStartend_list=nil
when(Temp=="ENTITIES"
while(!End_Flag
if(firstTime
fscanf(myDxf "%s\n" Entity_Start)
)
fscanf(myDxf "%s\n" Entity_Type)
case(upperCase(Entity_Type)
("LINE"
DxfLine(myDxf)
firstTime=nil
)
("CIRCLE"
DxfCircle(myDxf)
firstTime=nil
)
("LWPOLYLINE"
DxfLwployline(myDxf)
firstTime=nil
TestAddShape(Vertex_list)
)
)
when(Entity_Start=="ENDSEC" || Entity_Type=="ENDSEC";&& Start_Flag
End_Flag=t
)
)
)
)
close(myDxf)
else
printf("E - SetDefault: DXF file not exist,Creating config file.\n")
)
)
)
/*定义读取DXF中的直线部分,暂时没有使用*/
defun( DxfLine (DxfFile)
let((end)
end=nil
Line_list=nil
first_10=t
while(!end
fscanf(myDxf "%s\n" Value)
case(Value
("10"
fscanf(DxfFile "%s\n" LineStart_x)
first_10=nil
)
("20"
fscanf(DxfFile "%s\n" LineStart_y)
)
("11"
fscanf(DxfFile "%s\n" LineEnd_x)
)
("21"
fscanf(DxfFile "%s\n" LineEnd_y)
)
)
when(LineStart_x && LineStart_y && LineEnd_x && LineEnd_y
Line_list=cons(make_LineStruct( ?str_x atof(LineStart_x),?str_y atof(LineStart_y),?end_x atof(LineEnd_x),?end_y atof(LineEnd_y)) Line_list)
LineStart_x=nil
LineStart_y=nil
LineEnd_x=nil
LineEnd_y=nil
)
when(!first_10 && Value=="0"
end=t
)
)
)
)
/*定义读取DXF中的圆圈部分,暂时没有使用*/
defun( DxfCircle (DxfFile)
let((end CircleCertal_x CircleCertal_y CircleRadius)
end=nil
Circle=nil
Circle_list=nil
first_10=t
while(!end
fscanf(myDxf "%s\n" Value)
case(Value
("10"
fscanf(DxfFile "%s\n" CircleCertal_x)
first_10=nil
)
("20"
fscanf(DxfFile "%s\n" CircleCertal_y)
first_10=nil
)
("40"
fscanf(DxfFile "%s\n" CircleRadius )
first_10=nil
)
)
when(!first_10 && Value=="0"
end=t
)
when(CircleCertal_x && CircleCertal_y && CircleRadius
Circle_list=cons(make_CircleStruct( ?x atof(CircleCertal_x),?y atof(CircleCertal_y), ?r atof(CircleRadius)) Circle_list)
CircleCertal_x=nil
CircleCertal_y=nil
CircleRadius=nil
)
)
)
)
/*定义读取DXF中的多边形部分*/
|
|