【问题标题】:Access INSERT/Block content in DXF with ezdxf使用 ezdxf 访问 DXF 中的 INSERT/Block 内容
【发布时间】:2017-08-20 11:14:46
【问题描述】:

我正在尝试使用 python 2.7 和 ezdxf 模块将 DXF 文件的内容绘制到图像上。

我实现了读取和绘制 LINE、POLYLINE、CIRCLE,但我不知道如何处理 INSERT 元素。 我想这个 INSERT 元素(或相关块)包含其他元素,LINE,POLYLINE 等等......对吗?

这是我访问基本 DXF 元素的方法:

dwg = ezdxf.readfile(filename)
modelspace = dwg.modelspace()
for e in modelspace:
   analyseElement(e)

def analyseElement(e):
   if e.dxftype() == 'LINE':
       print("DXF LINE FOUND:")
       p1=e.dxf.start
       p2=e.dxf.end
      [...]

我是否希望从 INSERT 内容中探索和提取基本元素? 谢谢大家!

【问题讨论】:

    标签: python dxf


    【解决方案1】:

    BLOCK 是可重复使用的实体集合,可以像模型空间一样用于搜索或添加 DXF 实体。

    INSERT 实体是一个块参考,它决定了插入的块实体的位置、大小和旋转。并且 INSERT 可以有额外的 ATTRIB 实体,它们是由标签(名称)引用的文本值。

    BLOCK 定义存储在 Drawing.blocks 属性中:

    # iterate over all existing block definitions
    for block in dwg.blocks:
        for e in block:
            analyseElement(e)
    

    INSERT 实体存储在模型空间或另一个块定义中:

    for insert in modelspace.query('INSERT'):
        block = dwg.blocks[insert.dxf.name]
        for e in block:
             analyseElement(e)
    

    要搜索特定的 INSERT 实体:

    for insert in modelspace.query('INSERT[name=="MyBlock"]'):
        ...
    

    【讨论】:

    • 效果非常好!感谢 mozman 的帮助和出色的 ezdxf :)
    • 块和查询的链接不起作用,你能发布更新的链接
    猜你喜欢
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多