如何从 dxf 文档中的 LWPOLYLINE 获取 LINES 坐标?
我有以下代码:
import sys
import ezdxf
Coordenadas = str()
Coordenadas_texto = str()
try:
doc = ezdxf.readfile(str(arq)+".dxf")
except IOError:
print('Erro de arquivo. Certifique-se que é um arquivo .dxf')
sys.exit(1)
except ezdxf.DXFStructureError:
print('Arquivo invalido ou corrompoido.')
sys.exit(2)
msp = doc.modelspace()
for insert in msp.query('INSERT'):
block = doc.blocks[insert.dxf.name]
for e in block:
if e.dxftype() == 'LINE':
Coordenadas = Coordenadas + str(e.dxf.start) + "\n"
Coordenadas = Coordenadas + str(e.dxf.end) + "\n"
以上for
获取块“INSERT”并将它们拆分为我只能得到LINES。我尝试为 LWPOLYLINE 做同样的事情,但没有奏效。
下面的代码获取所有坐标,但我需要逐行过滤并获取坐标:
for flag_ref in msp.query('LWPOLYLINE'):
for entity in flag_ref:
print(entity)
下面的代码突然停止工作,我认为库 ezdxf 发生了变化。我收到错误
“LWPolyline”对象没有属性“virtual_entities”
for flag_ref in msp.query('LWPOLYLINE'):
for entity in flag_ref.virtual_entities():
if entity.dxftype() == 'LINE':
Coordenadas = Coordenadas + str(entity.dxf.start)+ "\n"
Coordenadas = Coordenadas + str(entity.dxf.end)+ "\n"