Get Attributes in dynamic block using ezdxf 0.14.1 and Python 3.8

1.1k Views Asked by At

I made a dynamic block using auotcad as attached and there are several attributes inside, i.e. "RXXX", "COOR". https://drive.google.com/file/d/1c8WdeAql1U5edFBKEK7coupx9ilX_Ga6/view?usp=sharing

I would like to extract the attributes following the guidance in the ezdxf document for wrapped blocks below but there is no luck. https://ezdxf.readthedocs.io/en/stable/tutorials/blocks.html?highlight=wrapped#evaluate-wrapped-block-references

Million thanks if someone has any idea on how to extract the attributes inside the dynamic block.

1

There are 1 best solutions below

1
On BEST ANSWER

The INSERT entity in this file is a regular INSERT and has no special features, print all tags and associated values:

import ezdxf

doc = ezdxf.readfile('Block with attribute.dxf')
msp = doc.modelspace()
for insert in msp.query('INSERT'):
    print(str(insert))
    print([(attrib.dxf.tag, attrib.dxf.text) for attrib in insert.attribs])

Result:

INSERT(#36E)
[('RXXX_001', 'R502b'), ('COOR', '"836689.0, 822839.6"'), 
('MAX_SPL', '64.6'), ('FLOOR_WITH_EXCEEDANCE', 'FLOOR_WITH_EXCEEDANCE'), 
('Exceedance', 'EXCEEDANCE'), ('SPL(BASE)', ''), ('MT_TYPEV3', ''), 
('TOWER', '5'), ('FLOOR', 'Typ'), ('UNIT', 'B'), ('ROOM', 'MBR'), 
('COOR_X', '836689.0044'), ('COOR_Y', '822839.5560')]