Passing object as param to Python COM server
Graham Fawcett
gmfawcett at operamail.com
Thu Nov 22 11:33:57 EST 2001
Following up to my own message, in case anyone else needs the answer
(or, more likely, I forget it and end up back at Google...)
You need to wrap the argument using win32com.client.Dispatch:
def QueryApp(self, app):
#Name should be a valid attribute of a PowerPoint.Application
app = win32com.client.Dispatch(app)
print app.Name # or whatever else you want to do.
> Hi folks,
>
> I've got a COM server written in Python, and it's running great (thank you to
> EVERYONE who made this marvellous tech possible). But I've got a question
> about passing parameters in method calls on my server.
>
> I have a VB script in PowerPoint that creates an instance of my server. I'd
> like to pass a reference to the PowerPoint application to my server, for
> example:
>
> 'in the PowerPoint macro,
> sub PassExample(pptapp as Application)
> Set myserver = CreateObject("UWindsor.MyServer")
> myserver.QueryApp pttapp
> end sub
>
> # in the server,
> def QueryApp(self, app):
> #Name should be a valid attribute of a PowerPoint.Application
> print app.Name
> ...
>
> Running the VB macro incurs an AttributeError: Name when the QueryApp method
> is called.
>
> The object (app) passed to my server is a PyIDispatch object. What do I have
> to do to make my server recognize this as a PowerPoint.Application object so
> that I can access its attributes (and hopefully invoke its methods)?
>
> Apologies for my lack of what is probably basic COM knowledge. Thanks,
> everyone.
>
> -- Graham
More information about the Python-list
mailing list