From Starbasic, return value from Python function

Creating a macro - Writing a Script - Using the API

From Starbasic, return value from Python function

Postby slang4201 » Thu May 21, 2009 12:45 am

Hi all,

I am looking for a method that I can - from StarBasic - invoke a Python function and get the value back. Any ideas?

Thanks!
----------------
-Steve
OOo 3.1 on Ms Windows XP
slang4201
 
Posts: 35
Joined: Wed Nov 12, 2008 9:21 pm

Re: From Starbasic, return value from Python function

Postby FJCC » Fri May 22, 2009 8:50 pm

I found this post on oooforum.org
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7790
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: From Starbasic, return value from Python function

Postby FJCC » Tue May 26, 2009 2:18 am

Looking into the information in the post I referenced previously, the basic method is easy. This code does the minimal task.

Code: Select all   Expand viewCollapse view
MSPF = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
scriptPro = MSPF.createScriptProvider("")
xScript = scriptPro.getScript("vnd.sun.star.script:PythonTest6.py$ProcessArray?language=Python&location=user")
ReturnVal = xScript.Invoke(Array(arg1()), Array(), Array())


The python file PythonTest6.py is stored as a script for an Ooo macro, but it needn't have anything to do with Ooo other than handle whatever gets passed to it. The array arg1() contains the arguments passed to the python script. I've read in the API documentation about the other two arrays that are arguments for xScript.invoke, but it made my head swim. Maybe I'll try that again later.

ReturnVal is whatever you put in the return statement of the python function. Remember that objects passed to and from python scripts by Ooo will be in the form of tuples on the python side.

Thanks to Villeroy for doing all the heavy lifting on this years ago.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7790
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 2 guests