DXF Entity Base Class

Common base class for all DXF entities and objects.

Warning

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

class ezdxf.entities.DXFEntity
dxf

The DXF attributes namespace:

# set attribute value
entity.dxf.layer = 'MyLayer'

# get attribute value
linetype = entity.dxf.linetype

# delete attribute
del entity.dxf.linetype
dxf.handle

DXF handle is a unique identifier as plain hex string like F000. (feature for experts)

dxf.owner

Handle to owner as plain hex string like F000. (feature for experts)

doc

Get the associated Drawing instance.

Changed in version 0.10: renamed from drawing

priority

Integer value defining order of entities: highest value first 100 (top) before 0 (default) before -100 (bottom), priority support not implemented yet, setting priority has no effect.

is_alive

Returns False if entity has been deleted.

dxftype() → str

Get DXF type as string, like LINE for the line entity.

__str__() → str

Returns a simple string representation.

__repr__() → str

Returns a simple string representation including the class.

has_dxf_attrib(key: str) → bool

Returns True if DXF attribute key really exist.

Raises DXFAttributeError if key is not an supported DXF attribute.

Changed in version 0.10: renamed from dxf_attrib_exists()

is_supported_dxf_attrib(key: str) → bool

Returns True if DXF attrib key is supported by this entity. Does not grant that attribute key really exist.

Changed in version 0.10: renamed from supports_dxf_attrib()

get_dxf_attrib(key: str, default: Any = None) → Any

Get DXF attribute key, returns default if key doesn’t exist, or raise DXFValueError if default is DXFValueError and no DXF default value is defined:

layer = entity.get_dxf_attrib("layer")
# same as
layer = entity.dxf.layer

Raises DXFAttributeError if key is not an supported DXF attribute.

set_dxf_attrib(key: str, value: Any) → None

Set new value for DXF attribute key:

entity.set_dxf_attrib("layer", "MyLayer")
# same as
entity.dxf.layer = "MyLayer"

Raises DXFAttributeError if key is not an supported DXF attribute.

del_dxf_attrib(key: str) → None

Delete DXF attribute key, does not raise an error if attribute is supported but not present.

Raises DXFAttributeError if key is not an supported DXF attribute.

dxfattribs() → dict

Returns a dict with all existing DXF attributes and their values.

update_dxf_attribs(dxfattribs: dict) → None

Set DXF attributes by a dict like {'layer': 'test', 'color': 4}.

set_flag_state(flag: int, state: bool = True, name: str = 'flags') → None

Set binary coded flag of DXF attribute name to 1 (on) if state is True, set flag to 0 (off) if state is False.

get_flag_state(flag: int, name: str = 'flags') → bool

Returns True if any flag of DXF attribute is 1 (on), else False. Always check only one flag state at the time.

has_extension_dict() → bool

Returns True if entity has an attached ExtensionDict.

get_extension_dict() → ExtensionDict

Returns the existing ExtensionDict or a new created one.

has_app_data(appid: str) → bool

Returns True if application defined data for appid exist.

get_app_data(appid: str) → Tags

Returns application defined data for appid.

Parameters

appid – application name as defined in the APPID table.

Raises

DXFValueError – no data for appid found

set_app_data(appid: str, tags: Iterable)

Set application defined data for appid as iterable of tags.

Parameters
  • appid – application name as defined in the APPID table.

  • tags – iterable of (code, value) tuples or DXFTag

discard_app_data(appid: str)

Discard application defined data for appid. Does not raise an exception if no data for appid exist.

has_xdata(appid: str) → bool

Returns True if extended data for appid exist.

get_xdata(appid: str) → Tags

Returns extended data for appid.

Parameters

appid – application name as defined in the APPID table.

Raises

DXFValueError – no extended data for appid found

set_xdata(appid: str, tags: Iterable)

Set extended data for appid as iterable of tags.

Parameters
  • appid – application name as defined in the APPID table.

  • tags – iterable of (code, value) tuples or DXFTag

discard_xdata(appid: str) → None

Discard extended data for appid. Does not raise an exception if no extended data for appid exist.

has_xdata_list(appid: str, name: str) → bool

Returns True if a tag list name for extended data appid exist.

get_xdata_list(appid: str, name: str) → Tags

Returns tag list name for extended data appid.

Parameters
  • appid – application name as defined in the APPID table.

  • name – extended data list name

Raises

DXFValueError – no extended data for appid found or no data list name not found

set_xdata_list(appid: str, name: str, tags: Iterable)

Set tag list name for extended data appid as iterable of tags.

Parameters
  • appid – application name as defined in the APPID table.

  • name – extended data list name

  • tags – iterable of (code, value) tuples or DXFTag

discard_xdata_list(appid: str, name: str) → None

Discard tag list name for extended data appid. Does not raise an exception if no extended data for appid or no tag list name exist.

replace_xdata_list(appid: str, name: str, tags: Iterable)

Replaces tag list name for existing extended data appid by tags. Appends new list if tag list name do not exist, but raises DXFValueError if extended data appid do not exist.

Parameters
  • appid – application name as defined in the APPID table.

  • name – extended data list name

  • tags – iterable of (code, value) tuples or DXFTag

Raises

DXFValueError – no extended data for appid found

has_reactors() → bool

Returns True if entity has reactors.

get_reactors() → List[str]

Returns associated reactors as list of handles.

set_reactors(handles: Iterable[str]) → None

Set reactors as list of handles.

append_reactor_handle(handle: str) → None

Append handle to reactors.

discard_reactor_handle(handle: str) → None

Discard handle from reactors. Does not raise an exception if handle does not exist.