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
|
.. _get_dxf_attributes:
Get DXF Attributes From Entities
================================
All DXF attributes of an entity are grouped in the namespace attribute :attr:`dxf`:
.. code-block:: Python
e.dxf.layer # layer of the entity as string
e.dxf.color # color of the entity as integer
The :attr:`dxf` namespace attribute has a :meth:`get` method, which can return a
default value if the attribute doesn't exist:
.. code-block:: Python
e.dxf.get('color', 9)
The attribute has to be supported by the DXF type otherwise a :class:`DXFAttributeError`
will be raised. You can check if an DXF attribute is supported by the method
:meth:`dxf.is_supported`:
.. code-block:: Python
line = msp.add_line((0, 0), (1, 0))
assert line.dxf.is_supported("text") is False
Optional DXF Attributs
----------------------
Many DXF attributes are optional, you can check if an attribute exists by the
:meth:`hasattrib` method:
.. code-block:: Python
assert line.dxf.hasattrib("linetype") is False
Default Values
--------------
Some DXF attributes have default values and this default value will be returned if the
DXF attribute doesn't exist:
.. code-block:: Python
assert line.dxf.linetype == "BYLAYER"
.. seealso::
**Tasks:**
- :ref:`Common graphical DXF attributes`
- :ref:`modify_dxf_attributes`
- :ref:`delete_dxf_attributes`
**Tutorials:**
- :ref:`tut_common_graphical_attributes`
- :ref:`tut_getting_data`
|