Kelie schrieb: > Hello, > > First of all, I suppose most users on this list would have no interest in this > topic. But I'm posting it anyway because it has puzzled for quite a while and > finally thanks to Thomas who found a solution. I also want to thank Ed Blake > who > showed me a solution with win32com. > > The question started with how to pass the right parameter to AutoCAD's > AddPoint > function. It is supposed to be Variant (three-element array of doubles) > according to the VBA API reference. The array.array function was the answer: > > 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." >
The reason for this is the following. Acad declares the AddPoint method with this signature: [id(0x0000061a), helpstring("Creates a Point object at a given location"), helpcontext(0x00010097)] HRESULT _stdcall AddPoint( [in] VARIANT Point, [out, retval] IAcadPoint** pPoint); so it expects a VARIANT specifying the Point coordinates. A VARIANT can contain a lot of different data types; it is unspecified above that Autocad only accepts a VARIANT containing a SAFEARRAY of doubles. By default, when you pass a Python sequence (tuple or list) for this parameter comtypes constructs a VARIANT containing a SAFEARRAY of VARIANTS. When you pass an array.array instance for the parameter, comtypes constructs a VARIANT containing a SAFEARRAY of type VT_R8 if the typecode of the array is 'd' (double), VT_R4 for the typecode 'f' (float), and so on. I assume this is the same for a lot of com servers requiring a VARIANT containing a SAFEARRAY. Thomas ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users