.
.
.
AcDbEntity
8
FORMAT
100
AcDbMText
10
73.6378494935
20
113.6626139923
30
0.2
40
3.0
41
0.0
71
1
72
1
1
10x10-100x100SampleText ← I want to get this text.
7
SLDTEXTSTYLE1
73
1
44
1.0
0
ENDBLK
5
196
330
194
100
AcDbEntity
8
0
100
AcDbBlockEnd
.
.
.
for entity in dxf.entities:
e = {}
e["type"] = entity.dxftype()
if e["type"] == "TEXT":
e["insert"] = entity.dxf.insert
e["text"] = entity.dxf.text
elif e["type"] == "MTEXT":
e["insert"] = entity.dxf.insert
e["raw_text"] = entity.get_text()
import ezdxf
doc = ezdxf.readfile('your_file.dxf')
msp = doc.modelspace()
for dimension in msp.query('DIMENSION'):
print("{} text: {}".format(str(dimension), dimension.dxf.text)
msp = dxf.modelspace()
for dimension in msp.query('DIMENSION'):
print("{} text: {}",format(str(dimension), dimension.dxf.text))
Result:
- - - - - - - - - -
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/ezdxf/lldxf/attributes.py", line 117, in get_attrib
return self._get_dxf_attrib(entity.tags)
File "/usr/local/lib/python3.7/site-packages/ezdxf/lldxf/attributes.py", line 137, in _get_dxf_attrib
return subclass_tags.get_first_value(self.code)
File "/usr/local/lib/python3.7/site-packages/ezdxf/lldxf/tags.py", line 134, in get_first_value
raise DXFValueError(code)
ezdxf.lldxf.const.DXFValueError: 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "python_read_dxf_ez.py", line 21, in <module>
print("{} text: {}",format(str(dimension), dimension.dxf.text))
File "/usr/local/lib/python3.7/site-packages/ezdxf/dxfentity.py", line 41, in __getattr__
return self._wrapper.get_dxf_attrib(attrib)
File "/usr/local/lib/python3.7/site-packages/ezdxf/dxfentity.py", line 203, in get_dxf_attrib
return dxfattr.get_attrib(self, key, default)
File "/usr/local/lib/python3.7/site-packages/ezdxf/lldxf/attributes.py", line 128, in get_attrib
raise DXFValueError("DXFAttrib '%s' does not exist." % key)
ezdxf.lldxf.const.DXFValueError: DXFAttrib 'text' does not exist.
- - - - - - - - - -
I also tried the following code:
Code1:
msp = dxf.modelspace()
for dimension in msp.query('DIMENSION'):
print("{} text: {}",format(str(dimension), dimension.dxf.text)
Code1 Result:
- - - - - - - - - -
- - - - - - - - - -
Code2:
msp = dxf.modelspace()
for dimension in msp.query('DIMENSION'):
print(str(dimension.dxf))
Code2 Result:
- - - - - - - - - -
- - - - - - - - - -
Code3:
msp = dxf.modelspace()
for dimension in msp.query('DIMENSION'):
print(str(dimension.dxf.txt))
Code3 Result:
- - - - - - - - - -
raise DXFValueError("DXFAttrib '%s' does not exist." % key)
ezdxf.lldxf.const.DXFValueError: DXFAttrib 'text' does not exist.
msp = dxf.modelspace()
for dimension in msp.query('DIMENSION'):
text = dimension.get_dxf_attrib('text', default=None)
if text is not None:
print(text)
for entity in dxf.entities:
if e["type"] == "MTEXT":
msp = dxf.modelspace()
for mtext in msp.query('MTEXT'):
print(mtext.dxfattribs())
Is there no way to get this?
thank you.
for entity in dxf.entities:
if entity.dxftype == "MTEXT":
print("MTEXT HIT")
else:
print(entity.dxftype)
DIMENSION(#104)
DIMENSION(#104)
msp = dxf.modelspace()
for mtext in msp.query('MTEXT'):
print(mtext.dxfattribs())