Attrib

The ATTRIB (DXF Reference) entity represents a text value associated with a tag. In most cases an ATTRIB is appended to an Insert entity, but it can also be used as a standalone entity.

Subclass of

ezdxf.entities.Text

DXF type

'ATTRIB'

Factory function

ezdxf.layouts.BaseLayout.add_attrib() (stand alone entity)

Factory function

Insert.add_attrib() (attached to Insert)

Inherited DXF attributes

Common graphical DXF attributes

Warning

Do not instantiate entity classes by yourself - always use the provided factory functions!

class ezdxf.entities.Attrib

ATTRIB supports all DXF attributes and methods of parent class Text.

dxf.tag

Tag to identify the attribute (str)

dxf.text

Attribute content as text (str)

property is_invisible: bool

Attribute is invisible if True.

property is_const: bool

This is a constant attribute if True.

property is_verify: bool

Verification is required on input of this attribute. (interactive CAD application feature)

property is_preset: bool

No prompt during insertion. (interactive CAD application feature)

property has_embedded_mtext_entity: bool

Returns True if the entity has an embedded MTEXT entity for multi-line support.

virtual_mtext_entity() MText

Returns the embedded MTEXT entity as a regular but virtual MText entity with the same graphical properties as the host entity.

plain_mtext(fast=True) str

Returns the embedded MTEXT content without formatting codes. Returns an empty string if no embedded MTEXT entity exist.

The fast mode is accurate if the DXF content was created by reliable (and newer) CAD applications like AutoCAD or BricsCAD. The accurate mode is for some rare cases where the content was created by older CAD applications or unreliable DXF libraries and CAD applications.

The accurate mode is much slower than the fast mode.

Parameters:

fast – uses the fast mode to extract the plain MTEXT content if True or the accurate mode if set to False

set_mtext(mtext: MText, graphic_properties=True) None

Set multi-line properties from a MText entity.

The multi-line ATTRIB/ATTDEF entity requires DXF R2018, otherwise an ordinary single line ATTRIB/ATTDEF entity will be exported.

Parameters:
  • mtext – source MText entity

  • graphic_properties – copy graphic properties (color, layer, …) from source MTEXT if True

embed_mtext(mtext: MText, graphic_properties=True) None

Set multi-line properties from a MText entity and destroy the source entity afterward.

The multi-line ATTRIB/ATTDEF entity requires DXF R2018, otherwise an ordinary single line ATTRIB/ATTDEF entity will be exported.

Parameters:
  • mtext – source MText entity

  • graphic_properties – copy graphic properties (color, layer, …) from source MTEXT if True

discard_mtext() None

Discard multi-line feature.

The embedded MTEXT will be removed and the ATTRIB/ATTDEF will be converted to a single-line attribute.