gpt4 book ai didi

python - 如何在 pyautocad 中访问 block 引用属性

转载 作者:行者123 更新时间:2023-12-01 09:32:54 36 4
gpt4 key购买 nike

如果 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))

更多详情可以查看https://gist.github.com/thengineer/7157510 .

关于python - 如何在 pyautocad 中访问 block 引用属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49802416/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com