[python-win32] problems in returning parameters using a COM client

Jens B. Jorgensen jens.jorgensen@tallan.com
Thu, 19 Dec 2002 13:39:41 -0600


Those parameters are most likely [in, out] params. This means you must 
pass something in. Try:

xpos, ypos = cd.GetPosition(0, 0)

George Vestergom wrote:

>Hello,
>
>Here's my problem:
>
>I'm writing routines to access the methods found in CorelDraw 6. I've
>used the MakePy utility to provide early-bound automation. Everything
>works fine, except I can't return values from certain methods.
>
>For example, one CorelDraw method returns 2 Long values: 
>     .GetPosition lngXPos, lngYPos
>
>     where lngXPos and lngYPos are the x and y position of the currently
>selected object.
>
>
>Using Python 2.2 and win32all build 148:
>
>  
>
>>>>from win32com.client import Dispatch
>>>>cd = Dispatch('CorelDraw.automation.6')
>>>>cd.Filenew()
>>>>cd.SetVisible(CDTrue)
>>>>        
>>>>
>
>  
>
>>>>## everything ok here, CorelDraw starts up and a new drawing surface
>>>>## is made visible.
>>>>        
>>>>
>
>  
>
>>>>## now draw a rectangle using the following method:
>>>>## .CreateRectangle lngTop, lngLeft, lngBottom, lngRight, 0
>>>>### (numbers are in CorelDraw units: tenths of a micron)
>>>>        
>>>>
>
>  
>
>>>>cd.CreateRectangle( 1500000, -1200000, 750000, -500000, 0)
>>>>        
>>>>
>
>  
>
>>>>## a rectangle is drawn and becomes the current selected object.
>>>>## now retrieve the current position of the rectangle:
>>>>        
>>>>
>
>  
>
>>>>x, y = cd.GetPosition()  # it should return x = -1200000, y = 1500000
>>>>        
>>>>
>
>  
>
>>>>## the following error is printed:
>>>>        
>>>>
>Traceback (most recent call last):
>  File "<pyshell#3>", line 1, in ?
>    cd.GetPosition()
>  File "<COMObject CorelDraw.automation.6>", line 2, in
>GetPosition
>com_error: (-2147352561, 'Parameter not optional.', None,
>None)
>  
>
>
>The following also do not work:
>  
>
>>>>(x, y) = cd.GetPosition()
>>>>cd.GetPosition()
>>>>print cd.GetPosition()
>>>>        
>>>>
>
>
>Here's an example using Excel 2000 VBA which works fine since the return
>variables must be  defined:
>
>Public Sub CorelDraw()
>  
>   Dim lngXPos As Long
>   Dim lngYPos As Long
>
>   ' create an automation object
>   Set cd = CreateObject("CorelDraw.Automation.6")
>   
>   ' create a rectangle and return current x, y position
>   With cd
>     .FileNew
>     .SetVisible -1     
>     .CreateRectangle 1500000, -1200000, 750000, -500000, 0
>     .GetPosition lngXPos, lngYPos
>     Debug.Print lngXPos, lngYPos
>   End With
>
>   Set cd = Nothing
>
>End Sub
>
>
>My question is this:
>
>Is it possible to retrieve these values in another way, maybe using
>PyIDispatch.InvokeTypes()? I can't see anything mentionned in Hammond's
>& Robinson's "Python Programming on Win32" to resolve this problem. 
>
>Here's the MakePy entry for this method:
>     def GetPosition(self, XPos=defaultNamedNotOptArg,
>YPos=defaultNamedNotOptArg):
>         return self._oleobj_.InvokeTypes(0x11, LCID, 1, (11,0),((16387,
>0), (16387, 0)),XPos, YPos)
>
>
>One idea I have in mind is to create an COM object from Excel and have
>python call a method in Excel which calls the GetPosition method in
>CorelDraw and stores the results on a worksheet. Python can then
>retrieve the values from this sheet. 
>
>Any suggestions would be appreciated.
>
>Thanks,
>George Vestergom
>
>_______________________________________________
>Python-win32 mailing list
>Python-win32@python.org
>http://mail.python.org/mailman/listinfo/python-win32
>  
>

-- 
Jens B. Jorgensen
jens.jorgensen@tallan.com

"With a focused commitment to our clients and our people, we deliver value through customized technology solutions"