Hi all,
I am having some trouble with AutoCAD
This works:
import array
import comtypes.client
app = comtypes.client.GetActiveObject("AutoCAD.Application")
ad = app.Documents.Add()
ms = ad.ModelSpace
pt1 = array.array('d', [1,1,0])
pt2 = array.array('d', [200,200,0])
line = ms.AddLine(pt1, pt2)
I can then use call most of the methods, and set / get properties for
the line object without any problems. Which is a pretty good start.
However, I get some problems class methods that return variants. For
example, when I call the array method:
line.ArrayRectangular(2,2,2,10.0,10.0,10.0)
I get this:
Traceback (most recent call last):
File "D:\Documents\Eclipse\py2autocad\py2autocad\test_array.py",
line 12, in <module>
line1.ArrayRectangular(2,2,2,10.0,10.0,10.0)
File "D:\Programs\Python25\Lib\site-packages\comtypes\automation.py",
line 424, in __ctypes_from_outparam__
result = self.value
File "D:\Programs\Python25\Lib\site-packages\comtypes\automation.py",
line 375, in _get_value
typ = _vartype_to_ctype[self.vt & ~VT_ARRAY]
KeyError: 9
This key error occurs in automation.py, and I have done some digging
around to see if I can understand what is going on. I am not very
clear - quite confused actually - but I think that .... the method is
returning a VT_ARRAY of VT_DISPATCH (i.e. 8201 = 8192 + 9). It is
then trying to convert the VT_DISPATCH to something compatible, and it
does this by looking for the key value of 9 in the dictionary
_ctype_to_vartype, and since there is no such key, it throws an error.
I have also noticed that in automation.py (line 740) it says:
# These are not yet implemented:
## POINTER(IUnknown): VT_UNKNOWN,
## POINTER(IDispatch): VT_DISPATCH,
My guess is that this is the problem - i.e. it has not been implemented.
Is there a work around?
Or can anyone give some hints about how to start implementing this missing bit?
Thanks for any help
-----------------
PS If I use oleview to look at the interface for the array method, I see this:
[id(0x00000506), helpstring("Creates an array of selected objects in a
rectangular pattern."), helpcontext(0x00010119)]
HRESULT ArrayRectangular(
[in] int NumberOfRows,
[in] int NumberOfColumns,
[in] int NumberOfLevels,
[in] double DistBetweenRows,
[in] double DistBetweenCols,
[in] double DistBetweenLevels,
[out, retval] VARIANT* pArrayObjs);
And for IDispatch, I see this:
[id(0x00000506), helpstring("Creates an array of selected objects in a
rectangular pattern."), helpcontext(0x00010119)]
VARIANT ArrayRectangular(
[in] int NumberOfRows,
[in] int NumberOfColumns,
[in] int NumberOfLevels,
[in] double DistBetweenRows,
[in] double DistBetweenCols,
[in] double DistBetweenLevels);
-----------------
Cheers
Patrick
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
comtypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/comtypes-users