Updating Python Script For AutoCAD Mechanical 2018

Updating Python Script For AutoCAD Mechanical 2018

Anonymous
Not applicable
1,082 Views
3 Replies
Message 1 of 4

Updating Python Script For AutoCAD Mechanical 2018

Anonymous
Not applicable

I have python scripts which interact with and control AutoCAD documents through comtypes, if the AutoCAD application and document are open. They work perfectly in AutoCAD Mechanical 2016. We have recently upgraded to AutoCAD Mechanical 2018 and the wheels have come off the wagon.  (Both running on Windows 10.)

 

The following line, directly after the imports (which I rewrote to include the package name for clarity)

 

app = comtypes.client.GetActiveObject("AutoCAD.Application")

 

...now fails with the error message:

 

COMerror: (-2147467262, 'No such interface supported', (None, None, None, 0, None))

 

This obviously breaks everything that follows-- no COM, no interface. Clearly something has changed from version to version relating to the com object, but I'm not sure what, or how I can specify the correct object here.  Can anyone help?

 

(I will note that I've tested the script in both versions of AutoCAD, both using the same test drawing, and that drawing was actually saved in AutoCAD 2013 format, for non-technical reasons. So it is unlikely to be anything about the file itself.)

0 Likes
1,083 Views
3 Replies
Replies (3)
Message 2 of 4

CodeDing
Advisor
Advisor

@Anonymous ,

 

I am not a Python guy, but perhaps this could solve your issue?

app = comtypes.client.GetActiveObject("AutoCAD.Application.18")

Best,

~DD

0 Likes
Message 3 of 4

Anonymous
Not applicable

@CodeDing it seems like it should be something related to that, but that doesn't work.  The error changes to:

 

OSError: [WinError -2147221005] Invalid Class String

 

I walked that number up from 18 to 30, just to experiment, and all gave the same results (Invalid Class String), except for 22 (again, 'no such interface supported.') 

 

 

0 Likes
Message 4 of 4

Anonymous
Not applicable

Can someone from AutoDesk weigh in, here?

Has the software changed from Mechanical 2016 to Mechanical 2018 in such a way that it would interfere with the Component Object Model?

0 Likes