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)
- property is_alive: bool
Is
Falseif entity has been deleted.
- property is_virtual: bool
Is
Trueif entity is a virtual entity.
- property is_bound: bool
Is
Trueif entity is bound to DXF document.
- property is_copy: bool
Is
Trueif 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
Trueif 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
Noneif this entity was not created by a block reference.
- dxftype() str
Get DXF type as string, like
LINEfor 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
Trueif DXF attribute key really exist.Raises
DXFAttributeErrorif key is not an supported DXF attribute.
- is_supported_dxf_attrib(key: str) bool
Returns
Trueif 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
DXFValueErrorif default isDXFValueErrorand no DXF default value is defined:layer = entity.get_dxf_attrib("layer") # same as layer = entity.dxf.layer
Raises
DXFAttributeErrorif 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
DXFAttributeErrorif 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
DXFAttributeErrorif key is not an supported DXF attribute.
- dxfattribs(drop: set[str] | None = None) dict
Returns a
dictwith 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
dictlike{'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 isFalse.
- get_flag_state(flag: int, name: str = 'flags') bool
Returns
Trueif any flag of DXF attribute is 1 (on), elseFalse. Always check only one flag state at the time.
- has_extension_dict
Returns
Trueif entity has an attachedExtensionDictinstance.
- get_extension_dict() ExtensionDict
Returns the existing
ExtensionDictinstance.- Raises:
AttributeError – extension dict does not exist
- new_extension_dict() ExtensionDict
Create a new
ExtensionDictinstance.
- discard_extension_dict() None
Delete
ExtensionDictinstance.
- discard_empty_extension_dict() None
Delete
ExtensionDictinstance when empty.
- has_app_data(appid: str) bool
Returns
Trueif 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
Trueif 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
Trueif 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
DXFValueErrorif 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
Trueif 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.