Get DXF Attributes From Entities

All DXF attributes of an entity are grouped in the namespace attribute dxf:

e.dxf.layer  # layer of the entity as string
e.dxf.color  # color of the entity as integer

The dxf namespace attribute has a get() method, which can return a default value if the attribute doesn’t exist:

e.dxf.get('color', 9)

The attribute has to be supported by the DXF type otherwise a DXFAttributeError will be raised. You can check if an DXF attribute is supported by the method dxf.is_supported():

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 hasattrib() method:

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:

assert line.dxf.linetype == "BYLAYER"