Every entity can have an extension dictionary, which can reference arbitrary DXF objects from the OBJECTS section but not graphical entities. Using this mechanism, several applications can attach data to the same entity. The usage of extension dictionaries is more complex than Extended Data (XDATA) but also more flexible with higher capacity for adding data.
Use the high level methods of
DXFEntity to manage
The main data storage objects referenced by extension dictionaries are:
Dictionary, structural container
DictionaryVar, stores a single string
XRecord, stores arbitrary data
Tutorial: Storing Custom Data in DXF Files
- class ezdxf.entities.xdict.ExtensionDict¶
Internal management class for extension dictionaries.
- __contains__(key: str)¶
Return key in self.
- __getitem__(key: str)¶
- __setitem__(key: str, value)¶
Set self[key] to value.
Only DXF objects stored in the OBJECTS section are allowed as content of the extension dictionary. DXF entities stored in layouts are not allowed.
DXFTypeError – invalid DXF type
- __delitem__(key: str)¶
Delete self[key], destroys referenced entity.
Returns count of extension dictionary entries.
- get(key: str, default=None) Optional[DXFEntity] ¶
Return extension dictionary entry key.
KeysViewof all extension dictionary keys.
ItemsViewfor all extension dictionary entries as (key, entity) pairs. An entity can be a handle string if the entity does not exist.
- discard(key: str) None ¶
Discard extension dictionary entry key.
- add_dictionary(name: str, hard_owned: bool = True) Dictionary ¶
Create a new
Dictionaryobject as extension dictionary entry name.
- add_dictionary_var(name: str, value: str) DictionaryVar ¶
Create a new
DictionaryVarobject as extension dictionary entry name.
Link obj to the extension dictionary as entry name.
Linked objects are owned by the extensions dictionary and therefore cannot be a graphical entity, which have to be owned by a
DXFTypeError – obj has invalid DXF type