python - 使用 ezdxf 删除 DXF 中的圆圈

标签 python dxf

我想删除 DXF 文件中的每个 Circle 实体。我正在使用 ezdxf,它似乎是完成此类工作的好工具。

我使用 ezdxf doc 编写代码,但我从 Python 中收到错误:

AttributeError: 'str' objet has no attribute 'destroy'

我不明白为什么。我使用了这个文档:http://pythonhosted.org/ezdxf/layouts.html#delete-entities

这是我的代码:

import dxfgrabber
import ezdxf

dwg = dxfgrabber.readfile("test.dxf")
print(dwg)
c = []
center_points = [entity.center for entity in dwg.entities if entity.dxftype == 'CIRCLE']
dxf = ezdxf.readfile("test.dxf")
modelspace = dxf.modelspace()
for point in center_points:
    modelspace.add_point(point)
    c.append(point)
modelspace.delete_entity('CIRCLE')
dxf.save()
print(c)

谢谢。

最佳答案

我成功了。我发布我的代码:

entities = dxf.entities
for e in entities:
        if e.dxftype() == 'CIRCLE':
            modelspace.delete_entity(e)

而不是:

modelspace.delete_entity('CIRCLE')

我认为它可能有更好的方法来做到这一点,但它确实有效。

关于python - 使用 ezdxf 删除 DXF 中的圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45139989/

相关文章:

autocad - 当具有凸出因子的 dxf 顶点后面没有端点时,这意味着什么?

python - 如何使用 dxfgrabber 或 ezdxf 包从 dxf 文件中查找实体的长度

java - 如何处理 kabeja 上的此错误?

python - PyOpenGl 验证失败

python - 对于使用 Python 3.6 的 Mayavi,PyQt5 失败为 "suitable UI Toolkit"

python - 如何解决我的 Django API 的 CORS 问题?

python - 如何在 Django 中更改上传文件的文件名?

python - Pandas read_csv 摆脱双引号

svg - 在保留图层的同时在 Inkscape CLI 中将 DXF 转换为 SVG

lisp - 为什么圆心坐标(键 10)与 DXF 数据中的原点不相关?