How to extract all coordinates from a dxf file

老子叫甜甜 提交于 2020-08-10 19:17:04

问题


Ive got a dxf file https://filebin.net/7l8izrv2js7doicc/5holes-8x8.dxf?t=9ro7k928 (download and name extension as .dxf) Im able to parse it for lines and all but I want to extract all coordinates now. The purpose is that if I get all the coordinates then Id be able to create a bounding box for all these coordinates. Since the drawing has curves and lines I dont know how to do it for curves etc.

===MY PARTIAL CODE TO DISPLAY LINES & pull out start & end point of lines====

flist=open("test2.dxf")

#fil.readlines()
# entityflist = open("filename.txt").readlines()
lst=[]

parsing = False
for line in flist:
    #print ("==================")
    if line.startswith("ENDSEC"):
        parsing = False
    if parsing:
        #print (line)
        lst.append(line)
        #Do stuff with data 
    if line.startswith("LINE"):
        parsing = True
        #print ("LINE")

# lines coordinates list
ts=(''.join(lst).split('LINE'))

#print out all the point coordinates of lines start & end
# i.e. 2 coordinate pairs for each line
for i in ts:
    print ((i.split()[19],i.split()[21]))
    print ((i.split()[15],i.split()[17]))

回答1:


Your link doesn't work but rather post a few lines of the file to show the structure, as it's bad practice to request people downloading huge files.

Looks like there is a library for handling dxf files called ezdxf. Here is a link to their guide on how to extract data from a dxf file



来源:https://stackoverflow.com/questions/63285763/how-to-extract-all-coordinates-from-a-dxf-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!