Page 1 of 1

API functions equivalent of UNO instructions

Posted: Thu Aug 09, 2018 4:28 pm
by V1ce
Hi,

I develop a small program with calc and writer and for some insruction i use UNO, but even if i use myDoc.lockControllers() and myDoc.addActionLock() my document move while the execution of the macro, i don't like this and i think this increase the time execution of the macro, expecially with LibreOffice, my macro work on both OpenOffice and LibreOffice and the macro take 2x more time to execute in Libro compared to Oo. I want to know if there are equivalent of these UNO instructions in API functions.

Code: Select all

' Here i open a new writer document from a model in hidden mode
opts(0).Name = "Hidden"
opts(0).Value = True
Url = ConvertToURL("C:\test\")
fn = "modele.ott"
oDoc = StarDesktop.loadComponentFromURL(Url & fn,"_blank",0,opts())
oDoc.storeAsUrl(Url & fn,Array()) 'Will overwrite existing file without warning!
publi= oDoc.CurrentController.Frame

' Here i go to a row of a sheet for hide it
args2(0).Name = "ToPoint"
args2(0).Value ="$"+NomFeuille+".$A$"+x
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())
dispatcher.executeDispatch(document, ".uno:HideRow", "", 0, Array())

'here i select a range of cells for copy it in the clipboard
args1(0).Name = "ToPoint"
args1(0).Value = "$"+NomFeuille+".$A$1:$"+NomFeuille+".$C$"+x
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

'Here i paste data previously copied on html format in the writer document 
args3(0).Name = "SelectedFormat"
args3(0).Value = 51
dispatcher.executeDispatch(publi, ".uno:ClipboardFormatItems", "", 0, args3())
dispatcher.executeDispatch(publi, ".uno:Save", "", 0, Array())
oDoc.close(true)

Thanks for your help

Re: Equivalent of UNO instructions in pure Basic

Posted: Thu Aug 09, 2018 6:54 pm
by Zizi64
I want to know if there are equivalent of these UNO instructions in pure basic.
There is not any equivalent in "pure BASIC" (StarBasic). But there are API functions, what you can call from the Basic - as you did it at the lines

Code: Select all

oDoc = StarDesktop.loadComponentFromURL(Url & fn,"_blank",0,opts())
oDoc.storeAsUrl(Url & fn,Array()) 'Will overwrite existing file without warning!
publi= oDoc.CurrentController.Frame
API: Application Programming Interface.

Re: Equivalent of UNO instructions in pure Basic

Posted: Fri Aug 10, 2018 6:49 am
by V1ce
Effectively i look for "API functions" to replace these UNO instructions.

Re: API functions equivalent of UNO instructions

Posted: Fri Aug 10, 2018 7:21 am
by Zizi64
See B. Marcelly's post in this thread:

viewtopic.php?f=20&t=42396


But - I just suppose it - you need rewrite all of UNO related commands to API based functions for decreasing of the execution time of the macro.

Where you want to use these command pairs in your code? (There are not such commands in your sample code...)

Re: API functions equivalent of UNO instructions

Posted: Fri Aug 10, 2018 8:25 am
by V1ce
I already read this thread and this help me for myDoc.lockControllers() and myDoc.addActionLock() . But it isnt enough, UNO commands that i use move the application when the macro execute. I effectively want to rewrite these instructions with API functions but i don't find the equivalent of this.
(There are not such commands in your sample code...)
There is, i use 3 UNO instructions in the program. If you want i can attach the entire macro with the file but in need to modify some informations before. In the macro i just use these 3 uno instructions, the rest is in basic. And the macro take time to execute when these UNO instructions are executed. My macro actually work but i want optimize it.

Code: Select all

' Here i open a new writer document from a model in hidden mode
opts(0).Name = "Hidden"
opts(0).Value = True
Url = ConvertToURL("C:\test\")
fn = "modele.ott"
oDoc = StarDesktop.loadComponentFromURL(Url & fn,"_blank",0,opts())
oDoc.storeAsUrl(Url & fn,Array()) 'Will overwrite existing file without warning!
publi= oDoc.CurrentController.Frame

' Here i go to a row of a sheet for hide it
args2(0).Name = "ToPoint"
args2(0).Value ="$"+NomFeuille+".$A$"+x
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())
dispatcher.executeDispatch(document, ".uno:HideRow", "", 0, Array())

'here i select a range of cells for copy it in the clipboard
args1(0).Name = "ToPoint"
args1(0).Value = "$"+NomFeuille+".$A$1:$"+NomFeuille+".$C$"+x
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

'Here i paste data previously copied on html format in the writer document
args3(0).Name = "SelectedFormat"
args3(0).Value = 51
dispatcher.executeDispatch(publi, ".uno:ClipboardFormatItems", "", 0, args3())
dispatcher.executeDispatch(publi, ".uno:Save", "", 0, Array())
oDoc.close(true)

Re: API functions equivalent of UNO instructions

Posted: Fri Aug 10, 2018 9:24 am
by Zizi64

Code: Select all

dispatcher.executeDispatch(publi, ".uno:Save", "", 0, Array())
You can use the

Code: Select all

oDoc.store()
API command instead of the UNO command. You can use it when the document has URL.
If the document hass not any URL yet, the you can use the StoreAsURL ot the StoreToURL command with parameters.
And you can check is the document has URL or not by the statement

Code: Select all

If oDoc.hasLocation() then

Re: API functions equivalent of UNO instructions

Posted: Fri Aug 10, 2018 9:30 am
by Zizi64

Code: Select all

' Here i go to a row of a sheet for hide it
args2(0).Name = "ToPoint"
args2(0).Value ="$"+NomFeuille+".$A$"+x
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())
dispatcher.executeDispatch(document, ".uno:HideRow", "", 0, Array())
Here is a sample code: how to hide a column (or a row) by API command (without UNO commands):
viewtopic.php?f=20&t=94572