如何计算已镜像的块或插入实体的位置?
在“wb”插入/块实体中有一个圆圈。我试图确定它在 msp 上的位置并画一个圆圈。附加的 DXF 文件中有 2 个“wb”块,其中一个是镜像的。
DXF 文件链接:https ://drive.google.com/file/d/1T1XFeH6Q2OFdieIZdfIGNarlZ8tQK8XE/view?usp=sharing
import ezdxf
from ezdxf.math import Vector
DXFFILE = 'washbasins.dxf'
OUTFILE = 'encircle.dxf'
dwg = ezdxf.readfile(DXFFILE)
msp = dwg.modelspace()
dwg.layers.new(name='MyCircles', dxfattribs={'color': 4})
def get_first_circle_center(block_layout):
block = block_layout.block
base_point = Vector(block.dxf.base_point)
circles = block_layout.query('CIRCLE')
if len(circles):
circle = circles[0] # take first circle
center = Vector(circle.dxf.center)
return center - base_point
else:
return Vector(0, 0, 0)
# block definition to examine
block_layout = dwg.blocks.get('wb')
offset = get_first_circle_center(block_layout)
for e in msp.query('INSERT[name=="wb"]'):
scale = e.get_dxf_attrib('xscale', 1) # assume uniform scaling
_offset = offset.rotate_deg(e.get_dxf_attrib('rotation', 0)) * scale
location = e.dxf.insert + _offset
msp.add_circle(center=location, radius=3, dxfattribs={'layer': 'MyCircles'})
dwg.saveas(OUTFILE)
上述代码不适用于 AutoCAD 文件中镜像的块。它的圆圈是在一个非常不同的位置绘制的。对于通过镜像命令放置的块,entity.dxf.insert 和 entity.dxf.rotation 返回的点和旋转与通过复制和旋转放置块的情况不同。
在这种情况下请提供帮助。同样,我们将如何处理线和圆实体?请分享相同的python函数/代码。