[Tutor] How to create array of variants?

Kelie kf9150 at gmail.com
Wed Jul 9 01:31:36 CEST 2008


Alan Gauld <alan.gauld <at> btinternet.com> writes:
> So if you pass in two Python lists containing:
> 
> DataType = [1001,1070]
> Data = ["Test_Application", 600]
> 
> Does it work?
> 
> If not what error do you get? (The full text please)
> 

Thanks Alan. This is the error I got:

Traceback (most recent call last):
  File "C:\Python25\codes\autocad\setxdata2.py", line 13, in <module>
    SetXData()
  File "C:\Python25\codes\autocad\setxdata2.py", line 10, in SetXData
    line.SetXData(dataType, dataValue)
_ctypes.COMError: (-2145320939, None, (u'Invalid argument type in SetXData
method', u'AutoCAD.Application', u'C:\\Program Files\\AutoCAD
2008\\HELP\\OLE_ERR.CHM', -2145320939, None))

> Alternatively does comtypes have a mechanism for converting Python
> types to VB/COM Variants?
> 

I think comtypes or pywin32 do take care of some conversion between Python 
types and VB types. But they don't work with AutoCAD.

Btw, this is the working code to draw a point in AutoCAD and you can't replace
pt = array.array('d', [0,0,0]) with pt = [0,0,0]. The latter gives an error:
COMError: (-2147024809, 'The parameter is incorrect.', (None, None, None, 0, 
None))

import array
import comtypes.client
acadApp = comtypes.client.GetActiveObject("AutoCAD.Application")
ms = acadApp.ActiveDocument.ModelSpace
pt = array.array('d', [0,0,0])
ms.AddPoint(pt)
print "Done."



More information about the Tutor mailing list