pyautocad 已有块属性(类别)的获取以及对象的方法输出(python)

代码如下:

from pyautocad import Autocad
import pythoncom


def run(path):
    pythoncom.CoInitialize()
    acad = Autocad(create_if_not_exists=True)
    acad.Application.Documents.Open(path)
    acad.ActiveDocument.Layers.Add("HIT_Layer")

    if acad:
        blocks = acad.doc.Blocks
        blocks = acad.best_interface(blocks)  
        for block in blocks:
            count = block.Count

            if "*Model_Space" == block.Name:
                for i in range(count):
                    item = block.Item(i)
                    print(item.EntityName)
                    print(dir(item))

            elif "*Paper_Space" == block.Name:  # 布局1
                pass
            elif "*Paper_Space0" == block.Name:  # 布局2
                pass
            else:
                pass
        return


if __name__ == "__main__":
    run("test.dwg")

1 autoCAD2010

输出如下:

AcDbBlockReference  # 类别

你可能感兴趣的:(Pycharm,小总结)