API functions equivalent of UNO instructions

Creating a macro - Writing a Script - Using the API

API functions equivalent of UNO instructions

Postby V1ce » Thu Aug 09, 2018 4:28 pm

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   Expand viewCollapse view
' 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
V1ce
 
Posts: 12
Joined: Thu Aug 02, 2018 4:39 pm

Re: Equivalent of UNO instructions in pure Basic

Postby Zizi64 » Thu Aug 09, 2018 6:54 pm

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   Expand viewCollapse view
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; LO4.4.7, LO5.4.7 on Win7x64Prof.
PortableApps, winPenPack: LO3.3.0-LO6.1.0 and AOO4.1.5
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: 7154
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Equivalent of UNO instructions in pure Basic

Postby V1ce » Fri Aug 10, 2018 6:49 am

Effectively i look for "API functions" to replace these UNO instructions.
OpenOffice 4.1.2
V1ce
 
Posts: 12
Joined: Thu Aug 02, 2018 4:39 pm

Re: API functions equivalent of UNO instructions

Postby Zizi64 » Fri Aug 10, 2018 7:21 am

See B. Marcelly's post in this thread:

https://forum.openoffice.org/en/forum/v ... 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; LO4.4.7, LO5.4.7 on Win7x64Prof.
PortableApps, winPenPack: LO3.3.0-LO6.1.0 and AOO4.1.5
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: 7154
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: API functions equivalent of UNO instructions

Postby V1ce » Fri Aug 10, 2018 8:25 am

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   Expand viewCollapse view
' 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
V1ce
 
Posts: 12
Joined: Thu Aug 02, 2018 4:39 pm

Re: API functions equivalent of UNO instructions

Postby Zizi64 » Fri Aug 10, 2018 9:24 am

Code: Select all   Expand viewCollapse view
dispatcher.executeDispatch(publi, ".uno:Save", "", 0, Array())

You can use the

Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
If oDoc.hasLocation() then
Tibor Kovacs, Hungary; LO4.4.7, LO5.4.7 on Win7x64Prof.
PortableApps, winPenPack: LO3.3.0-LO6.1.0 and AOO4.1.5
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: 7154
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: API functions equivalent of UNO instructions

Postby Zizi64 » Fri Aug 10, 2018 9:30 am

Code: Select all   Expand viewCollapse view
' 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):
https://forum.openoffice.org/en/forum/v ... 20&t=94572
Tibor Kovacs, Hungary; LO4.4.7, LO5.4.7 on Win7x64Prof.
PortableApps, winPenPack: LO3.3.0-LO6.1.0 and AOO4.1.5
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: 7154
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 10 guests