How can I get the LINES coordinates from a LWPOLYLINE in a dxf doc?
I have the following code:
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"
The for
above gets the block "INSERT" and splits them to I can get only LINES. I tried to do the same thing for LWPOLYLINE but it didn't work.
The code below gets all coordinates but I need to filter and get coordinates line by line:
for flag_ref in msp.query('LWPOLYLINE'):
for entity in flag_ref:
print(entity)
The code below stopped working suddenly, I think the library ezdxf changed. I'm getting the error
'LWPolyline' object has no attribute '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"