作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果 AutoCAD 绘图中的 Material list (BOM) 在“ block 引用”中,要使用 pyautocad 读取 BOM,我们可以使用以下代码读取它。
from pyautocad import Autocad
acad = Autocad()
for obj in acad.iter_objects(['Block']):
if obj.HasAttributes:
obj.GetAttributes()
但是它抛出异常
comtypes\automation.py,第 457 行,在 _get_valuetyp = _vartype_to_ctype[self.vt & ~VT_ARRAY] KeyError:9
如何使用 pyautocad 读取 AutoCAD 中的 BoM。
最佳答案
根据 pyautocad 存储库中记录的问题,https://github.com/reclosedev/pyautocad/issues/6 comtypes 存在与访问数组相关的问题。因此,要读取 block 引用,我们必须使用 win32com,如下所示:
import win32com.client
acad = win32com.client.Dispatch("AutoCAD.Application")
# iterate through all objects (entities) in the currently opened drawing
# and if its a BlockReference, display its attributes.
for entity in acad.ActiveDocument.ModelSpace:
name = entity.EntityName
if name == 'AcDbBlockReference':
HasAttributes = entity.HasAttributes
if HasAttributes:
for attrib in entity.GetAttributes():
print(" {}: {}".format(attrib.TagString, attrib.TextString))
关于python - 如何在 pyautocad 中访问 block 引用属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49802416/
OSError: [WinError -2147221005] Invalid class string 完整的回溯 During handling of the above exception, a
如果 AutoCAD 绘图中的 Material list (BOM) 在“ block 引用”中,要使用 pyautocad 读取 BOM,我们可以使用以下代码读取它。 from pyautocad
我是一名优秀的程序员,十分优秀!