Page 1 of 1

Extension can find macro in application but not in document

Posted: Thu May 13, 2021 1:08 pm
by DavidBo
I have made an extension in java which calls a macro "vnd.sun.star.script:Standard.GraphAlgorithm.eval?language=Basic&location=document"
But it cannot find the macro it throws an exception.
excp.png
excp.png (3.84 KiB) Viewed 2732 times
However, if I move my macro and module to "My macros and dialogs" and change the string to
"vnd.sun.star.script:Standard.GraphAlgorithm.eval?language=Basic&location=application"
it works. My document is a drawing.
The extension is written in java and gets the script by this code:

Code: Select all

     XScriptProviderFactory spFactory= (XScriptProviderFactory) UnoRuntime.queryInterface(XScriptProviderFactory.class,
				x.getValueByName("/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory"));
		XScriptProvider sp = spFactory.createScriptProvider(""); 
		XScript xScript = sp.getScript("vnd.sun.star.script:" + macroName);
Has anybody ever tried to execute a document macro from an extension or somewhere else where the string "vnd.sun.star.script:.." is needed?

Re: Extension can find macro in application but not in docum

Posted: Thu May 13, 2021 1:37 pm
by Villeroy
There can be many documents open, each one with the same macro on board. You should store that code globaly and pass over the document in question as an argument.

Re: Extension can find macro in application but not in docum

Posted: Thu May 13, 2021 3:30 pm
by JeJe
This works for me in Basic

IN CURRENT CONTROLLER DOCUMENT Standard library Module1

Code: Select all

sub test
	msgbox 4
end sub
In a library in MyMacros or in the document

Code: Select all


sub dodispatchCall()
	dim document   as object
	dim dispatcher as object
	document   = ThisComponent.CurrentController.Frame
	dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
	dispatchcall ="vnd.sun.star.script:Standard.Module1.test?language=Basic&location=document"
	dispatcher.executeDispatch(document, dispatchcall, "", 0, Array())
end sub

Re: Extension can find macro in application but not in docum

Posted: Thu May 13, 2021 3:37 pm
by JeJe
This works as well. Again, the document with the macro has to be the current component.

Code: Select all

 sub doScriptCall()
	st = "vnd.sun.star.script:Standard.Module1.test?language=Basic&location=document"
	dim provider as object,script as object
	provider = thisComponent.getScriptProvider
	script = provider.getScript(st)
	script.invoke(array(), array(), array())
end sub