Get coordinates of points in polyline

3,733 views
Skip to first unread message

Juju77

unread,
Jul 27, 2018, 5:40:37 AM7/27/18
to python-ezdxf
Hello everybody,

I search to obtain the 3D coordinates of all points that make my polyline :

ex: polyline1 : point1 (start) XY / point2 XY / point3  XY / ... / pointN (end) XY

I find a code to do this but it's for LINE and for a POLYLINE, the dxf.start crashes..

Can you help me please ! 



Manfred Moitzi

unread,
Jul 28, 2018, 4:46:05 AM7/28/18
to python-ezdxf
If you know which DXF entity you wanna examine, look at the ezdxf reference for available attributes and methods:



There you will find the Polyline.points() method: Iterate over all polyline points as (x, y[, z])-tuples, not as Vertex objects.

import ezdxf

dwg = ezdxf.readfile('your_dxf_file.dxf')
msp = dwg.modelspace()

# get all POLYLINE entities from model space
polylines = msp.query('POLYLINE')
for polyline in polylines:
    print('Polyline #{}'.format(polyline.dxf.handle))
    for i, location in enumerate(polyline.points()):
        print('Point at index {}: {}'.format(i, location))


Hint: most application using the LWPOLYLINE entity for 2D polylines.

Best Regards,
Manfred

Juju77

unread,
Jul 30, 2018, 2:47:43 AM7/30/18
to python-ezdxf
Hey, Yes well it runs perfectly!! 

I'm searching the same method to extract the coordinates of POINTS and POLYGON now and I will have the begining to build my script !
If you have some idea, I'm ready to explore them! :)

Thanks

Juju77

unread,
Jul 30, 2018, 2:51:17 AM7/30/18
to python-ezdxf
For 'POINT', I use point.dxf.location and it's ok ! :) 
I explore to get 'POLYGON' entities now !


Le vendredi 27 juillet 2018 11:40:37 UTC+2, Juju77 a écrit :

Manfred Moitzi

unread,
Jul 30, 2018, 3:19:30 AM7/30/18
to python-ezdxf
There exist not DXF entity POLYGON, I assume POLYGONS are implemented as closed POLYLINES.

Juju77

unread,
Jul 30, 2018, 3:32:44 AM7/30/18
to python-ezdxf
Yes we can say that polygons are closed by polylines, but in AutoCAD, I use the Polygon tool .. 
So How we can resolve the problem ? Have you got an idea ? :/ I search also !


Le vendredi 27 juillet 2018 11:40:37 UTC+2, Juju77 a écrit :
Reply all
Reply to author
Forward
0 new messages