Extension can find macro in application but not in document

Creating a macro - Writing a Script - Using the API

Extension can find macro in application but not in document

Postby DavidBo » Thu May 13, 2021 1:08 pm

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 1933 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   Expand viewCollapse view
     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
DavidBo
 
Posts: 27
Joined: Thu Mar 12, 2009 3:57 pm

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

Postby Villeroy » Thu May 13, 2021 1:37 pm

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
User avatar
Villeroy
Volunteer
 
Posts: 29907
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby JeJe » Thu May 13, 2021 3:30 pm

This works for me in Basic

IN CURRENT CONTROLLER DOCUMENT Standard library Module1

Code: Select all   Expand viewCollapse view
sub test
   msgbox 4
end sub


In a library in MyMacros or in the document

Code: Select all   Expand viewCollapse view

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: 1567
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby JeJe » Thu May 13, 2021 3:37 pm

This works as well. Again, the document with the macro has to be the current component.

Code: Select all   Expand viewCollapse view
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
JeJe
Volunteer
 
Posts: 1567
Joined: Wed Mar 09, 2016 2:40 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 12 guests