Updating Python Script For AutoCAD Mechanical 2018

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.)