From Starbasic, return value from Python function

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
slang4201
Posts: 35
Joined: Wed Nov 12, 2008 9:21 pm

From Starbasic, return value from Python function

Post by slang4201 »

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
FJCC
Moderator
Posts: 9273
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: From Starbasic, return value from Python function

Post by FJCC »

I found this post on oooforum.org
OpenOffice 4.1 on Windows 10 and Linux Mint
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: 9273
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: From Starbasic, return value from Python function

Post by FJCC »

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

Code: Select all

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.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Post Reply