-
I have a DXF file with sewing patterns. There are multiple layers for each size for e.g XXS, XS,....XXL. I want to save each layer as a separate DFX or pdf file. I am able to query the layers using I tried creating a new doc and adding the entities returned by the query, but I get this error. I am a complete beginner, and I am not sure how to proceed. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I added an example for that task. def main(filename: str):
source_doc = ezdxf.readfile(CWD / filename)
source_msp = source_doc.modelspace()
# create an EntityQuery container with all entities from the modelspace
source_entities = source_msp.query()
# get all layer names from entities in the modelspace:
all_layer_names = [e.dxf.layer for e in source_entities]
# remove unwanted layers if needed
for layer_name in all_layer_names:
# create a new document for each layer with the same DXF version as the
# source file
layer_doc = ezdxf.new(dxfversion=source_doc.dxfversion)
layer_msp = layer_doc.modelspace()
importer = Importer(source_doc, layer_doc)
# select all entities from modelspace from this layer (extended query
# feature of class EntityQuery)
entities: EntityQuery = source_entities.layer == layer_name # type: ignore
if len(entities):
importer.import_entities(entities, layer_msp)
# create required resources
importer.finalize()
layer_doc.saveas(CWD / f"{layer_name}.dxf") The example imports all entities from the modelspace into a new DXF document. The Importer add-on is required to also import the required resources used by the imported entities. Important advice: Basic concept of layers : https://ezdxf.mozman.at/docs/concepts/layers.html |
Beta Was this translation helpful? Give feedback.
I added an example for that task.