如何从 dxf 文件中提取所有坐标 [英] How to extract all coordinates from a dxf file

查看:151
本文介绍了如何从 dxf 文件中提取所有坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 dxf 文件 https://filebin.net/7l8izrv2js7doicc/5holes-8x8.dxf?t=9ro7k928(下载并扩展名为.dxf)我能够解析它的线条和所有但我现在想提取所有坐标.目的是如果我获得所有坐标,那么 Id 能够为所有这些坐标创建一个边界框.由于绘图有曲线和线条,我不知道如何为曲线等做.

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]))

推荐答案

您的链接不起作用,而是发布了几行文件来显示结构,因为要求人们下载大文件是不好的做法.

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.

看起来有一个名为 ezdxf 的用于处理 dxf 文件的库.这里有一个链接指向他们关于如何从 dxf 文件中提取数据的指南

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

这篇关于如何从 dxf 文件中提取所有坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆