Reputation: 1
I would like to know on which paperspace each entity in a DXF file would be located. I tried to find this by the code below, but the layout name I got is always the same one for each entity, while there are multiple number of paperspace in the DXF file. How can I get the paperspace for each entity in a DXF file?
# Read a DXF file
doc = ezdxf.readfile(file_path, encoding='shift-jis')
# Print names of Paperspaces
print(doc.layout_names_in_taborder())
# -> ['Model', '0A_Cover', '0B_Number', '0C_List', '01', '01H', '02', '02H', '03', '03H', '04', '04H', '05', '05H', '06', '06H', '07', '07H']
# Print the name of paperspace for each entity in the DXF file
for e in doc.entities:
# Paperspace Name
print(e.drawing.layout().name)
# -> 0A_Cover
# 0A_Cover
# 0A_Cover
# 0A_Cover
# 0A_Cover
# ...
# ...
# The paperspace name is always '0A_Cover' for all entities.
Upvotes: 0
Views: 1081
Reputation: 2239
Get the layout you want by the name as shown in tabs:
layout = doc.layout('0A_Cover')
Iterate over entitites of this layout:
for e in layout:
print(str(e))
or use an entity query:
lines = layout.query('LINE')
for line in lines:
print(str(line))
doc.entities
contains only the entities of the model space and the actual active paper space also known as the ENTITIES section of the DXF file.
To iterate over all entities in layouts (including 'Model') use:
for name in doc.layout_names_in_taborder():
for e in doc.layout(name):
print(str(e))
To iterate over all entities in layouts and blocks use:
for e in doc.chain_layouts_and_blocks():
print(str(e))
Iterate over all DXF entities of a DXF document use the entity database:
for e in doc.entitydb.values():
print(str(e))
Upvotes: 2