Reputation: 1082
I've a big problem using the import
method of Atocad ActiveX, the doc says its signature is:
RetVal = (Document)object.Import((String)FileName, (Variant (three-element array of doubles))InsertionPoint, (Double)ScaleFactor)
I'm using the following snippet of code:
import array
import comtypes.client
acad = comtypes.client.GetActiveObject("AutoCAD.Application")
doc = acad.ActiveDocument
ms = doc.ModelSpace
doc.Import("C:/path/to/the/drawing.dwg", array.array('d', [0, 0, 0]), 1.0)
But I get the following error:
Traceback (most recent call last):
File ".\script.py", line 30, in <module>
doc.Import("C:/path/to/the/drawing.dwg", array.array('d', [0, 0, 0]), 1.0
)
_ctypes.COMError: (-2147024809, 'The parameter is incorrect.', (u'Invalid argument', u'AutoCAD', u'C:\\Program Files\\Au
todesk\\AutoCAD 2015\\HELP\\OLE_ERR.CHM', -2145320901, None))
The problem is: which parameter is incorrect?!! Usually I always pass coordinates to autocad methods as I did in the second argument, it always works, can you please help me?
EDIT I've tried to pass [0.0, 0.0, 0.0]
same error
Upvotes: 1
Views: 2483
Reputation: 897
Not sure if you ever figured it out, but you get the COMError whenever there is a pending command in AutoCAD. The COMError is because both your script and the program itself are trying to access the same interface. You need to manually hit escape twice in AutoCAD and it shouldn't give you the error. If you ever find a way to make the python code use the COM interface to hit escape for you, let me know.
Upvotes: 1