我没有获得BlockReference的职位?

时间:2019-03-28 11:34:51

标签: python-2.7 autocad autocad-plugin

当我尝试制作Excel工作表时。需要AdcblockReference的名称和位置。但是当我尝试运行此代码获取属性错误时。所以我不知道下面给出的位置和名称是我的代码

    <PrecompileBeforePublish>True</PrecompileBeforePublish>
    <EnableUpdateable>False</EnableUpdateable>
    <DebugSymbols>True</DebugSymbols>
    <WDPMergeOption>CreateSeparateAssembly</WDPMergeOption>
    <UseFixedNames>True</UseFixedNames>

下面是错误的提示。

from os.path import join, dirname, abspath
from xlutils.copy import copy
import xlrd
import xlwt
from pyautocad import Autocad, APoint
import os
import win32com.client
from pyautocad import Autocad, APoint
from pyautocad.contrib.tables import Table
from comtypes import COMError

# Create workbook
book = xlwt.Workbook()
ws = book.add_sheet("ExportedData")
book.save("Exported.xls")

# Open the workbook
xl_workbook = xlrd.open_workbook("Exported.xls")
sheet_names = xl_workbook.sheet_names()

xl_sheet = xl_workbook.sheet_by_name(sheet_names[0])

wb = copy(xl_workbook)
sheet = wb.get_sheet(0)

dwgfiles = filter(os.path.isfile, os.listdir(os.curdir))

cwd = os.path.abspath(os.path.curdir)  # current working dir
print(cwd)
for f in dwgfiles:
    print("++++++++++++++++++++++++++++++")
    print("++++++++++++++++++++++++++++++")
    print("++++++++++++++++++++++++++++++")
    print("++++++++++++++++++++++++++++++")

    print(f)
    if f.endswith(".dwg"):
        print("sdaasdas")
        """ open Document"""
        acad = Autocad()
        print(cwd)
        acad.app.Documents.open(cwd + "/" + f)

        print(acad.doc.Name)

        num_cols = xl_sheet.ncols  # Number of columns
        idx = 1

        acad = win32com.client.Dispatch("AutoCAD.Application")

        doc = acad.ActiveDocument  # Document object

        print("MODEL SPACE")
        count=0
        for entity in acad.ActiveDocument.ModelSpace:
            name = entity.EntityName
            print(name)
            if name == 'AcDbBlockReference':
                print(name)
                count=count+1
                sheet.row(idx).write(1, entity.ObjectID)
                sheet.row(idx).write(2, cwd + "/" + f)
                sheet.row(idx).write(3,entity.IntersectionPoint)
                idx = idx + 1

        print(count)
        doc.Close(False)
        acad = None
wb.save("Exported.xls")

如果您建议我在AutoCAD上使用python的任何很好的教程,它都将非常有帮助

1 个答案:

答案 0 :(得分:1)

似乎输入错误。 您使用IntersectionPoint,而正确的名称应该是InsertionPoint(如VBA)或position(如ObjectARX)