def test_unbind_bound_entity(doc): e = factory.create_db_entry('POINT', {}, doc) doc.modelspace().add_entity(e) factory.unbind(e) assert e.is_alive, 'should not be destroyed' assert e.is_virtual, 'should be virtual entity' assert e.doc is None assert e.dxf.owner is None assert e.dxf.handle is None
def test_unbind_destroyed_entity(doc): e = factory.new('POINT') e.destroy() # should not raise an exception factory.unbind(e) assert e.is_alive is False
def test_unbind_unbound_entity(doc): e = factory.new('POINT') # should not raise an exception factory.unbind(e) assert e.is_alive, 'should not be destroyed'
def add_foreign_entity(self, entity: "DXFGraphic", copy=True) -> None: """Add a foreign DXF entity to a layout, this foreign entity could be from another DXF document or an entity without an assigned DXF document. The intention of this method is to add **simple** entities from another DXF document or from a DXF iterator, for more complex operations use the :mod:`~ezdxf.addons.importer` add-on. Especially objects with BLOCK section (INSERT, DIMENSION, MLEADER) or OBJECTS section dependencies (IMAGE, UNDERLAY) can not be supported by this simple method. Not all DXF types are supported and every dependency or resource reference from another DXF document will be removed except attribute layer will be preserved but only with default attributes like color ``7`` and linetype ``CONTINUOUS`` because the layer attribute doesn't need a layer table entry. If the entity is part of another DXF document, it will be unlinked from this document and its entity database if argument `copy` is ``False``, else the entity will be copied. Unassigned entities like from DXF iterators will just be added. Supported DXF types: - POINT - LINE - CIRCLE - ARC - ELLIPSE - LWPOLYLINE - SPLINE - POLYLINE - 3DFACE - SOLID - TRACE - SHAPE - MESH - ATTRIB - ATTDEF - TEXT - MTEXT - HATCH Args: entity: DXF entity to copy or move copy: if ``True`` copy entity from other document else unlink from other document """ foreign_doc = entity.doc dxftype = entity.dxftype() if dxftype not in SUPPORTED_FOREIGN_ENTITY_TYPES: raise DXFTypeError(f"unsupported DXF type: {dxftype}") if foreign_doc is self.doc: raise DXFValueError("entity from same DXF document") if foreign_doc is not None: if copy: entity = entity.copy() else: # Unbind entity from other document without destruction. factory.unbind(entity) entity.remove_dependencies(self.doc) # add to this layout & bind to document self.add_entity(entity)