Page 1 of 1

From Starbasic, return value from Python function

PostPosted: Thu May 21, 2009 12:45 am
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!

Re: From Starbasic, return value from Python function

PostPosted: Fri May 22, 2009 8:50 pm
by FJCC
I found this post on oooforum.org

Re: From Starbasic, return value from Python function

PostPosted: Tue May 26, 2009 2:18 am
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   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.