1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
.. _get_entity_content:
Get Content From DXF Entities
=============================
TEXT Entity
-----------
The content of the TEXT entity is stored in a single DXF attribute :attr:`Text.dxf.text`
and has an empty string as default value:
.. code-block:: Python
for text in msp.query("TEXT"):
print(text.dxf.text)
The :meth:`~ezdxf.entities.Text.plain_text` method returns the content of the TEXT
entity without formatting codes.
.. seealso::
**Classes**
- :class:`ezdxf.entities.Text`
**Tutorials**
- :ref:`tut_text`
MTEXT Entity
------------
The content of the MTEXT entity is stored in multiple DXF attributes. The content can be
accessed by the read/write property :attr:`~ezdxf.entities.MText.text` and the DXF attribute
:attr:`MText.dxf.text` and has an empty string as default value:
.. code-block:: Python
for mtext in msp.query("MTEXT"):
print(mtext.text)
# is the same as:
print(mtext.dxf.text)
.. important::
The line ending character ``\n`` will be replaced automatically by the MTEXT line
ending ``\P``.
The :meth:`~ezdxf.entities.MText.plain_text` method returns the content of the MTEXT
entity without inline formatting codes.
.. seealso::
**Classes**
- :class:`ezdxf.entities.MText`
- :class:`ezdxf.tools.text.MTextEditor`
**Tutorials**
- :ref:`tut_mtext`
MLEADER Entity
--------------
The content of MLEADER entities is stored in the :attr:`MultiLeader.context` object.
The MLEADER contains text content if the :attr:`context.mtext` attribute is not ``None``
and block content if the :attr:`context.block` attribute is not ``None``
.. seealso::
**Classes**
- :class:`ezdxf.entities.MultiLeader`
- :class:`ezdxf.entities.MLeaderContext`
- :class:`ezdxf.entities.MTextData`
- :class:`ezdxf.entities.BlockData`
- :class:`ezdxf.entities.AttribData`
**Tutorials**
- :ref:`tut_mleader`
Text Content
~~~~~~~~~~~~
.. code-block:: Python
for mleader in msp.query("MLEADER MULTILEADER"):
mtext = mleader.context.mtext
if mtext:
print(mtext.insert) # insert location
print(mtext.default_content) # text content
The text content supports the same formatting features as the MTEXT entity.
Block Content
~~~~~~~~~~~~~
The INSERT (block reference) attributes are stored in :attr:`MultiLeader.context.block`
as :class:`~ezdxf.entities.BlockData`.
.. code-block:: Python
for mleader in msp.query("MLEADER MULTILEADER"):
block = mleader.context.block
if block:
print(block.insert) # insert location
The ATTRIB attributes are stored outside the context object in :attr:`MultiLeader.block_attribs`
as :class:`~ezdxf.entities.AttribData`.
.. code-block:: Python
for mleader in msp.query("MLEADER MULTILEADER"):
for attrib in mleader.block_attribs:
print(attrib.text) # text content of the ATTRIB entity
DIMENSION Entity
----------------
Get real measurement determined by definition points:
.. code-block:: Python
for dimension in msp.query("DIMENSION"):
print(str(dimension))
print(f"Dimension Type: {dimension.dimtype}")
print(f"Measurement: {dimension.get_measurement()}")
==== ============================== ===
Type Dimension Type Measurement
==== ============================== ===
0 Linear and Rotated Dimension length in drawing units
1 Aligned Dimension length in drawing units
2 Angular Dimension angle in degree
3 Diameter Dimension length in drawing units
4 Radius Dimension length in drawing units
5 Angular 3P Dimension angle in degree
6 Ordinate Dimension feature location as :class:`~ezdxf.math.Vec3`
==== ============================== ===
Get measurement text. This is how the measurement text was rendered into the associated
geometry block by the CAD application as the DIMENSION entity was created:
.. code-block:: Python
for dimension in msp.query("DIMENSION"):
print(str(dimension))
print(f"Measurement Text: {dimension.dxf.text}")
======== ===
Text Measurement text rendered by CAD application
======== ===
``"<>"`` actual measurement
``""`` (empty string) actual measurement
``" "`` (space) measurement text is suppressed
other measurement text entered by the CAD user
======== ===
Get measurement text from text entities in the associated geometry block. This is the
actual measurement text displayed by CAD applications:
.. code-block:: Python
for dimension in msp.query("DIMENSION"):
print(str(dimension))
block = dimension.get_geometry_block()
if block is None:
print("Geometry block not found.")
continue
for entity in block.query("TEXT MTEXT"):
print(f"{str(entity)}: {entity.dxf.text}")
.. seealso::
**Tutorials:**
- :ref:`tut_linear_dimension`
**Classes:**
- :class:`ezdxf.entities.Dimension`
ACAD_TABLE Entity
-----------------
The helper function :func:`read_acad_table_content` returns the content of an ACAD_TABLE
entity as list of table rows. If the count of table rows or table columns is missing the
complete content is stored in the first row. All cells contain strings.
.. code-block:: Python
from ezdxf.entities.acad_table import read_acad_table_content
...
for acad_table in msp.query("ACAD_TABLE"):
content = read_acad_table_content(acad_table)
for n, row in enumerate(content):
for m, value in enumerate(row):
print(f"cell [{n}, {m}] = '{value}'")
.. important::
The ACAD_TABLE entity has only limited support to preserve the entity. There is no
support for adding a new ACAD_TABLE entity or modifying it's content.
INSERT Entity - Block References
--------------------------------
Get Block Attributes
~~~~~~~~~~~~~~~~~~~~
Get a block attribute by tag:
.. code-block:: Python
diameter = insert.get_attrib('diameter')
if diameter is not None:
print(f"diameter = {diameter.dxf.text}")
Iterate over all block attributes:
.. code-block:: Python
for attrib in insert.attribs:
print(f"{attrib.dxf.tag} = {attrib.dxf.text}")
.. important::
Do not confuse block attributes and DXF entity attributes, these are different
concepts!
Get Block Entities
~~~~~~~~~~~~~~~~~~
Get block entities as virtual DXF entities from an :class:`~ezdxf.entities.Insert` entity:
.. code-block:: Python
for insert in msp.query("INSERT"):
for entity in insert.virtual_entities():
print(str(entity))
Get Transformation Matrix
~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: Python
m = insert.matrix44()
This transformation matrix transforms the virtual block entities from the block reference
coordinate system into the :ref:`WCS`.
.. seealso::
**Tasks:**
- :ref:`add_blockrefs`
- :ref:`explode_block_references`
**Tutorials:**
- :ref:`tut_blocks`
**Basics:**
- :ref:`block_concept`
**Classes:**
- :class:`ezdxf.entities.Insert`
- :class:`ezdxf.entities.Attrib`
- :class:`ezdxf.entities.AttDef`
- :class:`ezdxf.math.Matrix44`
|