Reputation: 43
I am trying out the pyautocad package in python for AutoCAD automation. I tried the following code:
from pyautocad import Autocad, APoint
import win32com.client
AutoCAD = win32com.client.Dispatch("AutoCAD.Application.22")
acad = Autocad(create_if_not_exists = False)
acad.prompt("Hello, Autocad from Python\n")
print(acad.doc.Name)
p1 = APoint(0, 0)
p2 = APoint(50, 25)
for i in range(5):
text = acad.model.AddText('Hi %s!' % i, p1, 2.5)
acad.model.AddLine(p1, p2)
acad.model.AddCircle(p1, 10)
p1.y += 10
dp = APoint(10, 0)
for text in acad.iter_objects('Text'):
print('text: %s at: %s' % (text.TextString, text.InsertionPoint))
text.InsertionPoint = APoint(text.InsertionPoint) + dp
for obj in acad.iter_objects(['Circle', 'Line']):
print(obj.ObjectName)
i am getting an error: COMError: (-2147467262, 'No such interface supported', (None, None, None, 0, None)) . But the Autocad drawing has produced the circles and lines as per above code. The print command has not given any output. I feel this may be due to no data being passed from Autocad to the python.
Can anyone pls help me on this. I am using AutoCAD mechanical 2019 and python 3.7.7
Upvotes: 3
Views: 1751
Reputation: 1
Try to use acad.iter_objects_fast instead of acad.iter_objects. It will not solve your actual problem with acad.iter_objects, but will be work in a same way.
Upvotes: 0
Reputation: 1
I got the same error in this line 'for text in acad.iter_objects('Text'):
'
It's hard to find some solution about this error.
Now I have to turn to win32com to connect AUTOCAD as the webpage below: https://blog.csdn.net/Hulunbuir/article/details/83715279
Upvotes: 0