How can I reach coordinates in dxf file in Python.

996 views
Skip to first unread message

Sena Bahadıroğlu

unread,
Sep 4, 2020, 5:59:48 AM9/4/20
to python-ezdxf
Hi, I am new to CAD software and ezdxf. My operating system a Linux so I use LibreCAD.
My target is find the center of gravity in the dxf. I wrote code that finds the center of gravity with coordinate but I cant reach the coordinate int the dxf file in python. How can I reach coordinates in dxf file in Python.
 I tried read the file with python but this doesn't give me coordinates.
Also I tried groupby function and I got  something like this as output

Layer "KATMAN_1" contains following entities:
    INSERT(#42)
    INSERT(#47)
    INSERT(#4C)
    INSERT(#51)
    INSERT(#56)
    INSERT(#5B)  .....

So  How can I reach coordinates in dxf file in Python.

Manfred Moitzi

unread,
Sep 4, 2020, 7:36:56 AM9/4/20
to python-ezdxf
The insert location of a block reference (INSERT) is stored in the attribute Insert.dxf.insert

Sena Bahadıroğlu

unread,
Sep 5, 2020, 6:55:36 AM9/5/20
to python-ezdxf
Thanks for the answer but i'm new about this yet. My dxf file is ready. I'm running dxf file in the LibreCAD.  I'm trying to access the coordinates in dxf file. How can I take coordinates in dxf file. Unfortunately I can't figure out from the link you gave me. The link contains how to create but does not contain how to access the coordinates in the existing file. Can you give more details please? 

Sena Bahadıroğlu

unread,
Sep 7, 2020, 4:53:27 AM9/7/20
to python-ezdxf
Pleasee somebody help mee!! I'm just a student yet and immediately i need to find area and center of gravity in the dxf file. If I can reach the coordinates i think i can find the other things or can i just learn to find area in dxf file with python ?

5 Eylül 2020 Cumartesi tarihinde saat 13:55:36 UTC+3 itibarıyla Sena Bahadıroğlu şunları yazdı:

Sai Kumar Pulicharla

unread,
Oct 10, 2020, 7:53:35 AM10/10/20
to python-ezdxf
doc = ezdxf.readfile("filename.dxf")
msp = doc.modelspace()
for i in msp.query('INSERT'):
    print(i.dxf.insert)
Try this

Atakan Alkan

unread,
Oct 11, 2020, 8:45:16 AM10/11/20
to python-ezdxf
Merhaba sena, koordinatlarını bulmak istediğin şey doğrulardan veya arklardan oluşuyorsa aşağıdaki fonksiyonlar gibi bir şey yazabilirsin. Bu ezdxf kütüphanesi, senin kullandığın kütüphanede de muhtemelen vardır. Ben de yeni öğreniyorum umarım yardımcı olur.

import ezdxf
from ezdxf.math import Vector
dwg = ezdxf.readfile(filename)
modelspace = dwg.modelspace()

lines11.pngarc1.png

10 Ekim 2020 Cumartesi tarihinde saat 14:53:35 UTC+3 itibarıyla psaik...@gmail.com şunları yazdı:
Reply all
Reply to author
Forward
0 new messages