Class 如何从.DXF文件组织数据
我需要拆开一个GDS文件,对其进行更详细的分析 特别是,我需要计算设计层的数量、每个层中多段线的数量以及设计中每个多段线的顶点。Class 如何从.DXF文件组织数据,class,dxf,Class,Dxf,我需要拆开一个GDS文件,对其进行更详细的分析 特别是,我需要计算设计层的数量、每个层中多段线的数量以及设计中每个多段线的顶点。 我的问题是创建包含所有这些信息的类。最后,我希望能够通过指定以下内容来获取每个顶点的数据 Lyr[5].pl[3].vertx[7],其中5是第五层,3是该层中的第三条多段线,7是该多段线上的第七个顶点 我可以很好地获得图层和多段线,但是我无法思考如何开始添加顶点 顺便说一句,我不是直接使用GDS文件,而是一种名为.DXF的格式 每行一个简单的字符串文本文件 这是到目
我的问题是创建包含所有这些信息的类。最后,我希望能够通过指定以下内容来获取每个顶点的数据 Lyr[5].pl[3].vertx[7],其中5是第五层,3是该层中的第三条多段线,7是该多段线上的第七个顶点 我可以很好地获得图层和多段线,但是我无法思考如何开始添加顶点 顺便说一句,我不是直接使用GDS文件,而是一种名为.DXF的格式 每行一个简单的字符串文本文件 这是到目前为止我的代码
import sys #see sys modules using goggle
import string
import math
class layer:
def __init__(self,layer):
self.layer=layer
self.nplines=0
self.pl=[]
def add_pline(self,y):
self.pl.append(y)
def add_nplines(self):
self.nplines+=1
'''
class vertx
def __init__(self,n): ## Running out of ideas here
'''
def main():
my_file=sys.argv[1]
inFile=open(my_file,'r')
lyr=[]
nlayers=-1
## Get the layers
while 1:
s=inFile.readline()
if "CONTINUOUS" in s :
nlayers+=1
lyr.append(0)
s=inFile.readline() #burn one line in DXF file
s=inFile.readline() #name of the layer
lyr[nlayers]=layer(s) # save the layer
if 'POLYLINE' in s: break
inFile.close()
## Get the polylines
inFile=open(my_file,'r')
while 1:
s=inFile.readline()
if 'POLYLINE' in s:
s=inFile.readline() #burn a line
s=inFile.readline() #layer name
for i in range(0,nlayers+1):
if s==lyr[i].layer:
lyr[i].add_nplines()
if 'EOF' in s: break
inFile.close()
for i in range(0,nlayers+1):
print i,'Layer=',lyr[i].layer,' no plines= ',lyr[i].nplines
main()
您可以使用我的ezdxf包来处理DXF文件。它在PyPI上提供
ezdxf处理所有DXF版本,还可以将数据附加到现有DXF文件或创建新的DXF文件。请说明您的代码使用的语言是什么?此外,我怀疑“class”标记可能不合适。您可能会将其替换为您正在使用的编程语言的标记。
import ezdxf
dwg = ezdxf.readfile("your.dxf")
msp = dwg.modelspace() # contains all drawing entities
polylines = msp.query("POLYLINE") # get all polylines in modelspace
for polyline in polylines:
layer = polyline.dxf.layer # layername as string
points = polyline.points() # all vertices as (x, y [,z]) tuples
# for more see http://ezdxf.readthedocs.org