Replies: 3 comments 2 replies
-
Please specify your question, I don't understand when you mean block references and when you mean the content of blocks. |
Beta Was this translation helpful? Give feedback.
-
All block definitions are stored in the BLOCKS section of the DXF file. The content of the BLOCKS section is accessible by the attribute There are two kinds of block definitions:
Iteration over all blocks looks like this: import ezdxf
doc = ezdxf.readfile("your.dxf")
for layout in doc.blocks:
process_block_content(layout) Use following properties to check the type of a layout:
Next step ist to filter the block definitions from layouts and anonymous blocks: for layout in doc.blocks:
if (
layout.is_block_layout # is a block definition?
and not layout.block.is_anonymous # layout.block is the BLOCK entity of the block definition
and not layout.block.is_xref
):
process_block_content(layout) Processing the content entities is the easy part: def process_block_content(block_layout):
for entity in block_layout:
process_entity(entity) If you change the content of a block definition, you change the appearance of all block references with this definition! You cannot know where the block is being used, in model- or paper space, or in any other block definition, just by processing the block definition. So processing the INSERT entities from a model- or paper space layout is maybe the better way: msp = doc.modelspace()
unique_block_names = {insert.name for insert in msp.query("INSERT")}
for name in unique_block_names:
block_layout = doc.blocks.get(name)
if (
not layout.block.is_anonymous
and not layout.block.is_xref
):
process_block_content(block_layout) And don't worry about processing time, iteration over potentially thousands of entities is fast, even in Python - loading and saving time would be the bigger problem. |
Beta Was this translation helpful? Give feedback.
-
Goodnight! It looks like you were talking about the process_block_content function and accidentally misspelled by writing the "def process_clock_content" |
Beta Was this translation helpful? Give feedback.
-
This is more of a feature request or checking how to use the existing functionality.
I'd like to be able to get all the block definitions and their entities. So for example, If I have 3 separate block definitions say A, B, and C, and there are 4, 0, and 8 references respectively, is there a way that I can get 3 entities, one for each definition? I'd like to avoid having to query the whole modelspace for all INSERTS, and that also won't help me find definition B which has no references. But I would like to extract the entity associated with the definition. Is there a way to do this?
Beta Was this translation helpful? Give feedback.
All reactions