0

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?

  • Is there a reason that you can't open the dxf file with ezdxf, alter the object that ezdxf generates, then save the altered object as a dxf file again? If you do that then it would seem to be that you wouldn't need to know the location of the text in the file, although it's entirely possible that I'm missing something here. – Jack Taylor Nov 19 '20 at 14:53
  • 1
    That is EXACTLY what I'm trying to do....I just did a test and it works. Wow I was trying to overcomplicate this. Thank You @JackTaylor –  Nov 19 '20 at 15:27

2 Answers2

0

Try print(e.insert) to get the coordinates

William Baker Morrison
  • 1,642
  • 4
  • 21
  • 33
Neo
  • 1
0

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