Reading a block from one dxf file and inserting it into another one keeps failed
lyc12569 opened this issue · comments
yoimiya commented
I tried to read a block from one dxf file and insert it into another dxf file, but for some reason it kept failing. My code is as follows,which is simple. May I ask why it doesn't work?
path = r"D:/Wechatfile/WeChat Files/wxid_gfwt3ta1c2g622/FileStorage/File/2023-11/B.dxf"
doc = ezdxf.readfile(path)
msp = doc.modelspace()
blocks = msp.query('INSERT')
for block in blocks:
block_name = block.dxf.name
insertion_point = block.dxf.insert
if block_name == "BB":
block_def = doc.blocks[block_name]
print(f"Block Name: {block_name}")
print(f"Insertion Point: {insertion_point}")
doc2 = ezdxf.new('R2010')
flag = doc2.blocks.new(name='FLAG')
for entity in block_def:
flag.add_entity(entity.copy())
msp2 = doc2.modelspace()
msp2.add_blockref('FLAG', (0,0))
doc2.saveas("blockref_tutorial5.dxf")