# How Does the Uno Invoke Method Function? [closed]

This is a follow-up question to Execute a Python Macro (Function) From Base and Return Value to Base. While the use of the Invoke Method works, I do not understand how this method is able to pass values from one subroutine to the other. What variables (values) needs to be passed through the method and what values the method will return. Consequently, I have not been able to successfully modify the existing code structure. What I have found on the internet has proven to be to cryptic for me. I have been unable to locate an easy to comprehend tutorial that would review how the Invoke Function works.

In the example below, "a" essentially works as expected. I can pass a value through "a" and get a return value. However, what is the purpose of "b" and "c"? If I delete them, the script fails. The implication is that these variable must be required by the method for a reason. Are they parameters of some type? Unfortunately, I have not located an understandable explanation, at least for me. Uno Basic function below:

Function dblTestPython(dblValue) As Double
On Error Goto HandleError1001
dim a(0), b(0), c(0) as variant
a(0)= Forms("MainForm").Controls("Field1").value
scpr = ThisComponent.getScriptProvider
scmod = scpr.getScript("vnd.sun.star.script:call_me.py$call_me?language=Python&location=user") returnFromPython = scmod.invoke(a,b,c) print returnFromPython Exit Function HandleError1001: resume next End Function  Below is the Python script invoked by the Basic function above:  import os def call_me(a): z = int(a) * 5 return z  edit retag reopen merge delete ### Closed for the following reason the question is answered, right answer was accepted by Alex Kemp close date 2020-08-23 15:44:09.875650 ## 2 Answers Sort by » oldest newest most voted Hey! So I've been in touch with LibreOffice and UNO services for a week or so and after reading some posts and reading OOo API this is the way I believe invoke method works: [in] - argument is an input argument only and won't be referenced later [out] - means it's an output argument only, used to return a value by reference You got the following signature: any invoke ( [in] aParams, [out] aOutParamIndex, [out] aOutParam) Where: aParams contains the function name to call, and the params of the function; aOutParam contains the output parameters in the function that we're invoking signature; aOutParamIndex contains the position of the out or inout parameters (check the signature of the invoking function) in the list of arguments to the script. I'll use the example they're providing in the API: In a script file we have a function called showExample long showExample ( [inout] string a, [in] string b, [out] string c ) --> Notice that, we have two output parameters which are "a" and "c". To call the function, we would use: bar.invoke( {"showExample", "string_1", "string_2"}, aOutParamIndex, aOutParam) ---> showExample is the function I'm invoking ---> "string_1" is the string a parameter ---> aOutParamIndex={0,2}; --> referring to the showExample and "THIS-IS-IGNORED" aOutParam={"string from a", "string from c"}; --> corresponding to the two output parameters that we have more ## Comments Sorry, but it seems that this is beyond my comprehension. Fortunately, I can get the expected result, but I fail to understand the why. Hence the reason for this question. I also do not seem to have enough space in this comment section to review the questions your response provided. See my comment to Karolus of August 29, 2015. ( 2015-09-12 03:20:07 +0100 )edit I can post a longer comment concerning this syntax at the Open Office Forum if you want and post a link to that comment. ( 2015-09-14 01:45:47 +0100 )edit Hallo Imagine it as a kind of pipes between (different) Processes, the first is the Pipe for the Arguments (Stdin), the others for return-Values (Stout) and ErrorMessages (Stderr ) Edit: after reading the Api-reference I'm not sure about "the meaning" of second and third Argument-array :End_Edit maybe easier to understand if you write : Sub Main doc = thisComponent sprov = doc.getScriptProvider() scripturl = "vnd.sun.star.script:abc.py$test?language=Python&location=user"

method = sprov.getScript( scripturl )

print method.invoke(array(4,7), array(), array() )

End Sub


On the other side the simple function:

def test(*args):
return sum(args)

more

Thanks. It will take me a while to experiment. I tend not to comprehend how things work, until I get a working example where I can follow the flow of the code.

( 2015-08-16 23:46:08 +0100 )edit

Your script works. However, Positions 2 & 3 appear to be non-operative, even in my test code. I think that there is a syntax issue here. The example provided in the API appears to use a Python syntax construct, not a Basic construct. Consequently only "aParams" gets passed and returned. The other parameters "aOutParamIndex" and "aOutParam" do not seem to get passed nor returned.

( 2015-08-29 18:37:02 +0100 )edit