Extracting coordinates of all lines (in the generic sense), tried but failed to get everything

114 views
Skip to first unread message

Russell G

unread,
Mar 17, 2021, 1:40:37 PM3/17/21
to python-ezdxf
Hi,

I'm not the best Python programmer, but I have a problem I'm hoping to get some help with. I have a 2D plan view of pipelines etc (i.e. a 2D map with a series of polylines) in DXF, however when I've tried to export using ezdxf and my own code I only get some of the polylines, not the complete set despite them all being identified as polylines in AutoCAD. I was wondering if they were different entity types so I've been trying to export any coordinates I can get hold of.

Can anyone please give me any guidance on what I need to try?

Here is a copy of my hacky loop that tries to get any kind of coordinate it can and dump it to my Excel file:

for entity in msp:
    print('Entity #{}'.format(entity.dxf.handle))

    # If it's a LINE
    if entity.dxftype() == 'LINE':
        worksheet.write(row, col, entity.dxf.start[0])
        worksheet.write(row, col+1, entity.dxf.start[0])
        print("** WRITING VERTICES")
        row += 1
    
        worksheet.write(row, col, entity.dxf.end[0])
        worksheet.write(row, col, entity.dxf.end[1])
        print("** WRITING VERTICES")
        row += 1
    
    try:
        for i, location in enumerate(entity.vertices()):
            worksheet.write(row, col, location[0])
            worksheet.write(row, col+1, location[1])
            worksheet.write(row, col+2, entity.dxf.handle)
            print("** WRITING VERTICES")
            row += 1
    except:
        print("Entity had no Vertices")
   
    try:
        for i, location in enumerate(entity.points()):
            worksheet.write(row, col, location.x)
            worksheet.write(row, col+1, location.y)
            worksheet.write(row, col+2, entity.dxf.handle)
            print("** WRITING POINTS")
            row += 1
    except:
        print("Entity had no Polyline Points, moving to next entity")

Thanks,

Russell.

Reply all
Reply to author
Forward
0 new messages