API functions equivalent of UNO instructions

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
V1ce
Posts: 12
Joined: Thu Aug 02, 2018 4:39 pm

API functions equivalent of UNO instructions

Post 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
Last edited by V1ce on Fri Aug 10, 2018 6:59 am, edited 2 times in total.
OpenOffice 4.1.2
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Equivalent of UNO instructions in pure Basic

Post 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.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
V1ce
Posts: 12
Joined: Thu Aug 02, 2018 4:39 pm

Re: Equivalent of UNO instructions in pure Basic

Post by V1ce »

Effectively i look for "API functions" to replace these UNO instructions.
OpenOffice 4.1.2
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: API functions equivalent of UNO instructions

Post 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...)
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
V1ce
Posts: 12
Joined: Thu Aug 02, 2018 4:39 pm

Re: API functions equivalent of UNO instructions

Post 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)
OpenOffice 4.1.2
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: API functions equivalent of UNO instructions

Post 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
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: API functions equivalent of UNO instructions

Post 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
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Post Reply