python-2.7 - 我没有得到 BlockReference 的位置?
问题描述
当我尝试制作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
如果您向我推荐任何关于 AutoCAD 的 Python 好教程,这将非常有帮助
解决方案
好像是打字错误。您使用 IntersectionPoint
while 正确的应该是InsertionPoint
在 VBA 中或者可能position
在 ObjectARX 中
推荐阅读
- java - Oracle xmlsequence - java.sql.SQLException
- java - 如何将数据插入带有外键的表中?
- javascript - 在 javascript 上查询 Firebase
- spring-boot - 使用 Spring Boot 时如何模拟静态方法?
- python - 为什么 time.sleep(0) 让另一个线程在删除 time.sleep 时继续运行直到循环完成?
- r - 使用 mutate 和 min_rank 根据其他两列中的值创建排名列
- .net - Dotnet:如何在 Mac 中关闭/打开?
- javascript - 提交表单后,Thymeleaf 文本从按钮和下拉项中消失
- java - 在 ScheduledThreadPoolExecutor 中覆盖泛型方法的问题
- postgresql - 表“cloudsqladmin.public.heartbeat”的自动真空