Я не получаю Позицию BlockReference? - PullRequest
0 голосов
/ 28 марта 2019

, когда я пытаюсь сделать лист Excel. которому нужно имя и позиция AdcblockReference. но когда я пытаюсь запустить этот код, получаю ошибку атрибута. поэтому я не знаю, как получить указанную ниже позицию и имя, это мой код

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")

ниже - ошибка, которую я получаю.

Traceback (most recent call last):
  File "auto1.py", line 64, in <module>
    sheet.row(idx).write(3,entity.IntersectionPoint)
  File "D:\autocad_test\venv\lib\site-packages\win32com\client\dynamic.py", line 527, in __getattr__
    raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: <unknown>.IntersectionPoint

очень полезно, если вы предложите мне хороший урок Python по AutoCAD

1 Ответ

1 голос
/ 28 марта 2019

Кажется, это опечатка. Вы используете IntersectionPoint, в то время как правильное значение должно быть InsertionPoint, как в VBA, или, возможно, position, как в ObjectARX

.
...