Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 我没有得到BlockReference的职位?_Python 2.7_Autocad_Autocad Plugin - Fatal编程技术网

Python 2.7 我没有得到BlockReference的职位?

Python 2.7 我没有得到BlockReference的职位?,python-2.7,autocad,autocad-plugin,Python 2.7,Autocad,Autocad Plugin,当我尝试制作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.cli

当我尝试制作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

回溯(最近一次呼叫最后一次):
文件“auto1.py”,第64行,在
sheet.row(idx).write(3,实体.IntersectionPoint)
文件“D:\autocad\u test\venv\lib\site packages\win32com\client\dynamic.py”,第527行,位于\uu getattr中__
提高属性错误(“%s.%s%”(self.\u用户名,attr))
AttributeError:。相交点

如果您向我推荐任何关于AutoCAD上python的好教程,那将非常有帮助。它似乎是键入错误。
您使用的是
IntersectionPoint
,而正确的应该是
InsertionPoint
,如在VBA中,或者可能是
position
如在ObjectARX中,这要感谢它的工作。我还有一个dought,如何获得BlockReference名称和Cordinate。我没有与pyton合作,所以我不确定。但在VBA中,BlockReference具有属性名或方法GetName。在ObjectARX中,您需要获取BlockDefinition,并从BlockDefinition中读取名称,以及您所说的“Cordinate”是什么意思?InsertionPoint不正是坐标@CAD开发者:是的,谢谢。你有VBA教程的链接吗?我正在使用ZWCAD,只需按F1键就可以获得许多示例的帮助。顺便问一下:你会接受这个答案吗?我非常喜欢声誉;)