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.

property is_alive: bool

Is False if entity has been deleted.

property is_virtual: bool

Is True if entity is a virtual entity.

property is_bound: bool

Is True if entity is bound to DXF document.

property is_copy: bool

Is True if the entity is a copy.

property uuid: UUID

Returns a UUID, which allows to distinguish even virtual entities without a handle.

Dynamic attribute: this UUID will be created at the first request.

property source_of_copy: DXFEntity | None

The immediate source entity if this entity is a copy else None. Never references a destroyed entity.

property origin_of_copy: DXFEntity | None

The origin source entity if this entity is a copy else None. References the first non-virtual source entity and never references a destroyed entity.

property has_source_block_reference: bool

Is True if this virtual entity was created by a block reference.

property source_block_reference: Insert | None

The source block reference (INSERT) which created this virtual entity. The property is None if this entity was not created by a block reference.

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.

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.

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(drop: set[str] | None = None) dict

Returns a dict with all existing DXF attributes and their values and exclude all DXF attributes listed in set drop.

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

Returns True if entity has an attached ExtensionDict instance.

get_extension_dict() ExtensionDict

Returns the existing ExtensionDict instance.

Raises:

AttributeError – extension dict does not exist

new_extension_dict() ExtensionDict

Create a new ExtensionDict instance.

discard_extension_dict() None

Delete ExtensionDict instance.

discard_empty_extension_dict() None

Delete ExtensionDict instance when empty.

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) None

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) None

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) None

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) None

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.