我想在现有的 dxf 文件上找到一个块(代表一扇门)并用一条直线替换它(即关上门)。
我的想法是找到插入块的点,然后从该点沿块的较大尺寸画一条线。
为此,我需要找到块的总宽度和高度。我曾尝试使用explode 和virtual_entities 来尝试分析组成块的各个线和多段线,但我最终得到的点甚至与dxf 文件中显示的点都不接近。
我还需要它在 dxf 文件上的确切位置。当我使用 dxf.insert 时,我得到的点与图层上的实际插入点坐标不同。
我正在使用 matplotlib 在绘图上显示实体,这是我尝试过的代码示例:
for insert in msp.query('INSERT'):
insertion_point = insert.dxf.insert
for e in insert.virtual_entities():
if e.dxftype == 'LINE':
a = e.dxf.start
b = e.dxf.end
x = [a[0], b[0]]
y = [a[1], b[1]]
plt.plot(x, y, 'b')
elif e.dxftype == 'LWPOLYLINE':
poly = np.array(list(e.vertices()))
plt.plot(poly[:,0],poly[:,1],'b')