'How to read text location from ezdxf
I created a program that searches through multiple subdirectories, reads a specific .txt file and finds the relevant info then stores it in a list. It then needs to open a dxf, read the text, if a certain condition is met, replace the text from list, then write the text to the same location. The problem is I can't find a way to find the text location from reading the ezdxf documentation. In the example, they're using a line
print("LINE on layer: %s\n" % e.dxf.layer)
print("start point: %s\n" % e.dxf.start)
print("end point: %s\n" % e.dxf.end)
so I just modified mine to read
def print_entity(e):
print(e.dxf.text)
print(e.dxftype())
print(e.pos)
print(e.start)
print(e.location)
for e in msp.query('TEXT[layer=="TEXT"]'):
print_entity(e)
However none of those give me the position of the text. Any ideas?
Solution 1:[1]
Try print(e.insert) to get the coordinates
Solution 2:[2]
Found in EzDxf documentation
get_placement() ? Tuple[TextEntityAlignment, Vec3, Optional[Vec3]]
Returns a tuple (align, p1, p2), align is the alignment enum TextEntityAlignment, p1 is the alignment point, p2 is only relevant if align is ALIGNED or FIT, otherwise it is None.
https://ezdxf.readthedocs.io/en/stable/dxfentities/text.html#ezdxf.entities.Text.get_placement
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | William Baker Morrison |
| Solution 2 | Hugues Paquet Blanchette |
