[dxf] ignore unreferenced internal dxf blocks
This commit is contained in:
parent
bbe3586ba9
commit
cf0a245143
2 changed files with 42 additions and 1 deletions
|
|
@ -192,8 +192,37 @@ def read(
|
|||
|
||||
top_name, top_pat = _read_block(msp)
|
||||
mlib = Library({top_name: top_pat})
|
||||
|
||||
blocks_by_name = {
|
||||
bb.name: bb
|
||||
for bb in lib.blocks
|
||||
if not bb.is_any_layout
|
||||
}
|
||||
|
||||
referenced: set[str] = set()
|
||||
pending = [msp]
|
||||
seen_blocks: set[str] = set()
|
||||
while pending:
|
||||
block = pending.pop()
|
||||
block_name = getattr(block, 'name', None)
|
||||
if block_name is not None and block_name in seen_blocks:
|
||||
continue
|
||||
if block_name is not None:
|
||||
seen_blocks.add(block_name)
|
||||
for element in block:
|
||||
if not isinstance(element, Insert):
|
||||
continue
|
||||
target = element.dxfattribs().get('name')
|
||||
if target is None or target in referenced:
|
||||
continue
|
||||
referenced.add(target)
|
||||
if target in blocks_by_name:
|
||||
pending.append(blocks_by_name[target])
|
||||
|
||||
for bb in lib.blocks:
|
||||
if bb.name == '*Model_Space':
|
||||
if bb.is_any_layout:
|
||||
continue
|
||||
if bb.name.startswith('_') and bb.name not in referenced:
|
||||
continue
|
||||
name, pat = _read_block(bb)
|
||||
mlib[name] = pat
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue