x_ScriptContext = uno.getScriptContext()
if (x_ScriptContext <> .nil) then
do
x_ComponentContext = x_ScriptContext~getComponentContext
x_Desktop = x_ScriptContext~getDesktop
x_Document = x_ScriptContext~getDocument
end
else
do
x_ComponentContext = UNO.connect()
service = "com.sun.star.frame.Desktop"
s_Desktop = x_ComponentContext~getServiceManager~XMultiServiceFactory~createInstance(service)
x_Desktop = s_Desktop~XDesktop
x_Document = x_Desktop~getCurrentComponent()
end
x_MultiServiceFactory = x_ComponentContext~getServiceManager()~XMultiServiceFactory
s_DispatchHelper = x_MultiServiceFactory~createInstance("com.sun.star.frame.DispatchHelper")
x_DispatchHelper = s_DispatchHelper~XDispatchHelper
x_DispatchProvider = x_Desktop~XDispatchProvider
MacroURL = "vnd.sun.star.script:BakkMacros.x_Sample.rex?language=ooRexx&location=user"
parameters = uno.CreateArray(.UNO~PROPERTYVALUE, 2)
parameters[1] = uno.createProperty("arg1", 5)
parameters[2] = uno.createProperty("arg2", 2)
r = x_DispatchHelper~executeDispatch(x_DispatchProvider, MacroURL, "", 0, parameters)
.bsf.dialog~messageBox("Result of x_Sample.rex: " || r~result, "IT Works", "information")
MacroURL = "vnd.sun.star.script:BakkMacros.x_Sample.addition?language=Basic&location=application"
r = x_DispatchHelper~executeDispatch(x_DispatchProvider, MacroURL, "", 0, parameters)
.bsf.dialog~messageBox("Result of x_Sample.addition (Star Basic Macro): " || r~result, -
"IT Works", "information")
::requires UNO.CLS
The called ooRexx macro (x_Sample.rex):
info = "Adding: " || ARG(1) || " + " || ARG(2) || " using ooRexx"
.bsf.dialog~messageBox(info, "IT Works", "information")
return (ARG(1) + ARG(2))
::requires BSF.CLS
The called Basic macro (Store to
"My Macros", Library name: "BakkMacros", Module: "x_Sample"):
REM ***** BASIC *****
Sub Main
RunMacro
End Sub
Function addition(arg1, arg2 as Integer) as Integer
' view that we are currently using Star Basic
MsgBox("Adding: " & arg1 & " + " & arg2 & " using Star Basic", 64, "IT Works")
' return calculation
' to calculate make sure the parameters are Integers
addition = CInt(arg1) + CInt(arg2)
End Function
Sub RunMacro
' create the Dispatcher service
oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
Automating Open Office â~@~S ooRexx Nutshells Page 29
' prepare parameters as array
Dim a(1) As New com.sun.star.beans.PropertyValue
a(0).Name = "arg1" : a(0).Value = 7
a(1).Name = "arg2" : a(1).Value = 1
' macro URL to addition function above
sMacroURL = "vnd.sun.star.script:BakkMacros.x_Sample.addition?language=Basic&location=application"
' call addition function
r = oDisp.executeDispatch(StarDesktop, sMacroURL, "", 0, a())
' view result
MsgBox("Result of x_Sample.addition: " & r.result, 64, "IT Works")
' macro URL to x_Sample.rex
sMacroURL = "vnd.sun.star.script:BakkMacros.x_Sample.rex?language=ooRexx&location=user"
' call x_Sample.rex and use the same parameters again
r = oDisp.executeDispatch(StarDesktop, sMacroURL, "", 0, a())
' show result
MsgBox("Result of x_Sample.addition: " & r.result, 64, "IT Works")
End Sub