关于DXF文件格式说明在上一篇已经有较为详细的说明,由于这个程序是为了特定项目所服务的,所以对文件有一定的限制条件:在DXF文件中只存在一个多边形实体,获取这个多边形所有的顶点坐标即可。
class Point:
'this class is used to record coordinate of vertex'
def __init__(self,x,y):
self.x = x
self.y = y
point是记录点坐标的数据结构
下面是相应的读取处理代码:
from Point import Point
class DxfReader:
def __init__(self,file):
self.file = file
#pointList record the vertexes of polyline
self.pointList = []
def readDXF(self):
line1 =""
line1 = self.file.readline()
line2=""
counter = 0
# record the sum of vertex
sumofVertext = 1
x = 0
y =0
for line in file:
#find the polyline
if line1.strip() == "0" and line.strip()== "LWPOLYLINE":
for linetemp in file:
if line2.strip() =="90":
numofVertex = int(linetemp.strip())
# while 10 occur,then the x is recorded
if line2.strip() == "10":
x = float(linetemp.strip())
if line2.strip() == "20":
y = float(linetemp.strip())
point = Point (x,y)
self.pointList.append(point)
counter += 1
if counter >= numofVertex:
break
line2 = linetemp
line1 = line
file.close()
if __name__=="__main__":
file = open("D:\\test.dxf")
reader = DxfReader(file)
reader.readDXF()
for temp in reader.pointList:
print str(temp.x) + " " + str(temp.y)
分享到:
相关推荐
C#读取dxf中的圆坐标,并且把所有坐标绘图显示出来
python读取数据库数据对dxf文件进行标注并另存,链接数据库,读取数据,根据数据对dxf文件进行方框标注,并判断文字区域旋转角,最后另存
Python语言读取dxf文件数据,得到其中的线条及点坐标
c#经典读取dxf文件,识别点圆坐标!并保存!
读取dxf文档信息,解析直线坐标信息,通过雷赛运动控制卡进行直线插补运动。
读取DXF文件并在OpenGL中显示.读取DXF文件并在OpenGL中显示.
DXF格式读取dxf文件格式读取dxf文件格式 读取dxf文件格式 读取dxf文件格式
本程序可以很好地读取DXF文件,可以输出直线(c_Line)多段线(c_Poly)圆(c_Cir)圆弧(c_Arc)顶点(c_Poi),很实用
本程序采用VC++编写,实现的功能为读取dxf中的几何元素并进行显示,同时在窗口中有平移
C读取DXF文件并用GDI的相关API显示出图形。 只读取了LINE和CIRCLE实体以作示例。 用VC++6.0编译通过。
NetDxf读取DXF文件
简单的读取dxf文件中直线,圆弧,多段线,并实现拖动和放大缩小。还不能实际应用可以借鉴下。
在vc++里读取DXF文件 并对其图形进行任意角度的旋转,显示旋转后的图形
用labview读取dxf文件的案列,labview是面向工程师的语言
C# 读取dxf文件,显示到视图,可以通过鼠标移动,放大缩小。
OPENGL读取DXF格式文件
使用netdxf(C#)框架实现dxf文件读取与导出坐标
labview 读DXF文件,验证ok。
是一个读取dxf文件的程序
读取dxf文件,可以获取每个实体的属性,如坐标,圆心,弧度等关键属性