Entity Database¶
The EntityDB is a simple key/value database to store
DXFEntity objects by it’s handle,
every Drawing has its own EntityDB, stored in
the Drawing attribute entitydb.
Every DXF entity/object, except tables and sections, are represented as
DXFEntity or inherited types, this entities are stored in the
EntityDB, database-key is the dxf.handle as plain hex
string.
All iterators like keys(), values(), items() and __iter__()
do not yield destroyed entities.
Warning
The get() method and the index operator [], return destroyed
entities and entities from the trashcan.
- class ezdxf.entitydb.EntityDB¶
- __getitem__(handle: str) DXFEntity¶
Get entity by handle, does not filter destroyed entities nor entities in the trashcan.
- __delitem__(handle: str) None¶
Delete entity by handle. Removes entity only from database, does not destroy the entity.
- __len__() int¶
Count of database items.
- __iter__() Iterator[str]¶
Iterable of all handles, does filter destroyed entities but not entities in the trashcan.
- get(handle: str) DXFEntity | None¶
Returns entity for handle or
Noneif no entry exist, does not filter destroyed entities.
- next_handle() str¶
Returns next unique handle.
- keys() Iterable[str]¶
Iterable of all handles, does filter destroyed entities.
- items() Iterable[Tuple[str, DXFEntity]]¶
Iterable of all (handle, entities) pairs, does filter destroyed entities.
- add(entity: DXFEntity) None¶
Add entity to database, assigns a new handle to the entity if
entity.dxf.handleisNone. Adding the same entity multiple times is possible and creates only a single database entry.
- new_trashcan() Trashcan¶
Returns a new trashcan, empty trashcan manually by: : func:Trashcan.clear().
- trashcan() Trashcan¶
Returns a new trashcan in context manager mode, trashcan will be emptied when leaving context.
- purge() None¶
Remove all destroyed entities from database, but does not empty the trashcan.
- query(query: str = '*') EntityQuery¶
Entity query over all entities in the DXF document.
- Parameters:
query – query string
See also
Entity Space¶
- class ezdxf.entitydb.EntitySpace(entities: Iterable[DXFEntity] | None = None)¶
An
EntitySpaceis a collection ofDXFEntityobjects, that stores only references toDXFEntityobjects.The
Modelspace, anyPaperspacelayout andBlockLayoutobjects have anEntitySpacecontainer to store their entities.- __getitem__(index) DXFEntity¶
Get entity at index item
EntitySpacehas a standard Python list like interface, therefore index can be any valid list indexing or slicing term, like a single indexlayout[-1]to get the last entity, or an index slicelayout[:10]to get the first 10 or fewer entities aslist[DXFEntity]. Does not filter destroyed entities.
- __len__() int¶
Count of entities including destroyed entities.
- has_handle(handle: str) bool¶
Trueif handle is present, does filter destroyed entities.
- purge()¶
Remove all destroyed entities from entity space.
- clear() None¶
Remove all entities.