Extension can find macro in application but not in document

Creating a macro - Writing a Script - Using the API
Post Reply
DavidBo
Posts: 27
Joined: Thu Mar 12, 2009 3:57 pm

Extension can find macro in application but not in document

Post 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 2658 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?
Apache Open Office 4.1.9 Windows 10
User avatar
Villeroy
Volunteer
Posts: 30803
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Post 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.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
JeJe
Volunteer
Posts: 2059
Joined: Wed Mar 09, 2016 2:40 pm

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

Post 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
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
Posts: 2059
Joined: Wed Mar 09, 2016 2:40 pm

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

Post 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
Openoffice 4.1.6
Windows 8
Post Reply