def duplicate_entity(self, entity: DXFEntity) -> DXFEntity: """ Duplicates `entity` and its sub entities (VERTEX, ATTRIB, SEQEND) and store them with new handles in the entity database. Graphical entities have to be added to a layout by :meth:`~ezdxf.layouts.BaseLayout.add_entity`. To import DXF entities from another drawing use the :class:`~ezdxf.addons.importer.Importer` add-on. A new owner handle will be set by adding the duplicated entity to a layout. """ new_entity: DXFEntity = entity.copy() new_entity.dxf.handle = self.next_handle() factory.bind(new_entity, entity.doc) return new_entity
def duplicate_entity(self, entity: DXFEntity) -> DXFEntity: """ Duplicates `entity` and its sub entities (VERTEX, ATTRIB, SEQEND) and store them with new handles in the drawing database. This is the recommend method to duplicate DXF entities in a drawing. Graphical entities have to be added to a layout by :meth:`~ezdxf.layouts.BaseLayout.add_entity`, for other DXF entities: DON'T DUPLICATE THEM. To import DXF entities into another drawing use the :class:`~ezdxf.addons.importer.Importer` add-on. An existing owner tag is not changed because this is not the domain of the :class:`EntityDB` class, will be set by adding the duplicated entity to a layout. This is not a deep copy in the meaning of Python, because handles and links are changed. """ new_entity = entity.copy() # type: DXFEntity new_entity.dxf.handle = self.next_handle() self.add(new_entity) return new_entity
def duplicate_entity(self, entity: DXFEntity) -> DXFEntity: """Duplicates `entity` and its sub entities (VERTEX, ATTRIB, SEQEND) and store them with new handles in the entity database. Graphical entities have to be added to a layout by :meth:`~ezdxf.layouts.BaseLayout.add_entity`. DXF objects will automatically added to the OBJECTS section. To import DXF entities from another drawing use the :class:`~ezdxf.addons.importer.Importer` add-on. A new owner handle will be set by adding the duplicated entity to a layout. """ doc = entity.doc assert doc is not None, "valid DXF document required" new_handle = self.next_handle() new_entity: DXFEntity = entity.copy() new_entity.dxf.handle = new_handle factory.bind(new_entity, doc) if isinstance(new_entity, DXFObject): # add DXF objects automatically to the OBJECTS section doc.objects.add_object(new_entity) return new_entity