我正在尝试打印多个布局上的块的属性:
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.PaperSpace:
name = entity.EntityName
if name == 'AcDbBlockReference':
HasAttributes = entity.HasAttributes
if HasAttributes:
for attrib in entity.GetAttributes():
print(" {}: {}".format(attrib.TagString, attrib.TextString))
输出:
DRAWING-NO: xxxx
REV: D
CI-NO_SHORT:
CI-NO_LONG:
SCALE: NONE
SHEET: 2
TOTAL_SHEETS: 17
CADFILE: xxxx_D.DWG
您会看到它仅打印活动选项卡中的属性,而不打印其他 16 个属性。
我发现我需要使用 win32com 并且不能使用 pyautocad here。使用 pyautocad,我能够迭代所有布局,但无法访问属性。
我可能建议迭代块集合,然后迭代每个布局容器的组件,例如:
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 block in acad.ActiveDocument.Blocks:
if block.isLayout and not block.ModelType
for entity in block:
name = entity.EntityName
if name == 'AcDbBlockReference':
HasAttributes = entity.HasAttributes
if HasAttributes:
for attrib in entity.GetAttributes():
print(" {}: {}".format(attrib.TagString, attrib.TextString))