OSError: [WinError -2147221005] Invalid class string
full traceback
During handling of the above exception, another exceptio
That specific error occurs because your program can't open AutoCAD properly; but when I open AutoCAD by myself and then run your code, it appears the following error:
_ctypes.COMError: (-2147467262, 'No compatible interface', (None, None, None, 0, None))
In my experience, COMError
often appears due to a poor connection with the used program. I solve that kind of problem by combining win32com
with pyautocad
. For this particular case, it would be something like this:
from pyautocad import Autocad, APoint
import win32com.client
AutoCAD = win32com.client.Dispatch("AutoCAD.Application")
acad = Autocad(create_if_not_exists = False)
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(['Hi']):
print('text: %s at: %s' % (text.TextString, text.InsertionPoint))
text.InsertionPoint = APoint(text.InsertionPoint) + dp
for line in acad.iter_objects(dont_cast = True):
print(line.ObjectName)
AutoCAD.Visible = True