ScriptForge Library (A hint concerning LibreOffice>=V7.1)

Creating a macro - Writing a Script - Using the API

ScriptForge Library (A hint concerning LibreOffice>=V7.1)

Postby Lupp » Sun Mar 28, 2021 2:47 am

Starting with V 7.1 libreOffice comes with a new library of Basic modules developed partly under LibO's VBAsupport 1 and using Class Modules.
There isn't yet a satisfying documentation, and the package obviously isn't fully QA'd/debugged. For interested users it should be worth a try. I started looking at the function ExecuteBasicScript() and inspecting its steps for an example, but can not yet judge if the complexity is fully justified. (For "followers": The called function must be given including the library name. ...) There is also a function ExecutePythonScript().
In short: Something's going on.
On Windows 10: LibreOffice 7.2 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 3121
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: ScriptForge Library (A hint concerning LibreOffice>=V7.1

Postby JeJe » Sun Mar 28, 2021 12:30 pm

Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1605
Joined: Wed Mar 09, 2016 2:40 pm

Re: ScriptForge Library (A hint concerning LibreOffice>=V7.1

Postby eeigor » Sun Mar 28, 2021 12:51 pm

1. ScriptForge Dictionary vs com.sun.star.container.EnumerableMap (??)
2. Is it worth cluttering libraries with such primitive procedures?
Code: Select all   Expand viewCollapse view
Sub RefreshDataPilot()
   Dim oSheet As Object, oTables As Object, oTable As Object

   'oSheet = ThisComponent.Sheets.getByIndex(3)
   oSheet = ThisComponent.CurrentController.ActiveSheet
   oTables = oSheet.getDataPilotTables()

   'Dim sTableName As String
   'sTableName = oTables.ElementNames(0)  '"DataPilot1"
   'oTable = oTables.getByName(sTableName)
   oTable = oTables.getByIndex(0)  'only one table

   oTable.refresh
End Sub

3. TrimExt() 'Extended? Duplicates Basic Trim, but adds something else to the spaces ("[\s]+")
Code: Select all   Expand viewCollapse view
   If Len(InputStr) > 0 Then
      sTrim = SF_String.ReplaceRegex(InputStr, REGEXLTRIM, "")  'Trim left
      sTrim = SF_String.ReplaceRegex(sTrim, REGEXRTRIM, "")  'Trim right
   End If

Recently I dealt with this problem...
Code: Select all   Expand viewCollapse view
   With oReplace: .SearchRegularExpression = True: .SearchWords = False
      .setSearchString("^\s+|\s+$")  'any spaces at the start or end…
      .setReplaceString("")  '…replaces with null string
   End With
   nCount = oRanges.replaceAll(oReplace)

   With oReplace
      .setSearchString("\s{2,}")  '2+ consecutive spaces…
      .setReplaceString(" ")  '…replaces with one
   End With
   nCount = nCount + oRanges.replaceAll(oReplace)

4. Compare:
oTextSearch = SF_Utils._GetUNOService("TextSearch") ' instead of:
oTextSearch = CreateUnoService("com.sun.star.util.TextSearch")
...isolates but does not teach
<...>
Last edited by eeigor on Sun Mar 28, 2021 1:11 pm, edited 4 times in total.
Ubuntu 18.04 LTS • LibreOffice 7.2.0.2 Community
eeigor
 
Posts: 174
Joined: Sun Apr 12, 2020 10:56 pm

Re: ScriptForge Library (A hint concerning LibreOffice>=V7.1

Postby JeJe » Sun Mar 28, 2021 12:54 pm


LibreOffice scripters get the benefit of a new set of libraries called ScriptForge, which can be called from Basic or Python with some handy capabilities such as automation of Calc sheets, file and directory handling, and a large set of functions for handling arrays, strings and more.


https://www.theregister.com/2020/12/03/ ... e_71_beta/

Edit:
better link
https://blog.documentfoundation.org/blo ... libraries/
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1605
Joined: Wed Mar 09, 2016 2:40 pm

Re: ScriptForge Library (A hint concerning LibreOffice>=V7.1

Postby JeJe » Sun Mar 28, 2021 1:25 pm

Interesting - it looks like a lot of work has gone into it.

The library needs to be loaded. I don't use any of the built-in Basic Libraries as I prefer things to be self-contained... I think having the code in-library so I don't have to worry about seeing if another library is loaded... and loading it if not... is far easier... even if it means duplication of code.

Loading a massive library is also overkill if you just want one little function in it. If you make extensive use of this for a project that would be different. I saw the timer and hopefully thought they've provided a timer control (!)... but its just to measure elapsed time for running other macros.
Last edited by JeJe on Sun Mar 28, 2021 2:04 pm, edited 1 time in total.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1605
Joined: Wed Mar 09, 2016 2:40 pm

Re: ScriptForge Library (A hint concerning LibreOffice>=V7.1

Postby eeigor » Sun Mar 28, 2021 2:00 pm

As well as me: variations with the RegEx function did not suit me. I also wanted to access the RegEx object, but there is no such object. But the search is organized using objects and methods/properties as expected.
Any code is useful for learning, no doubt. And there is probably still a lot to learn.
Ubuntu 18.04 LTS • LibreOffice 7.2.0.2 Community
eeigor
 
Posts: 174
Joined: Sun Apr 12, 2020 10:56 pm

Re: ScriptForge Library (A hint concerning LibreOffice>=V7.1

Postby Lupp » Sun Mar 28, 2021 2:46 pm

I generally doubt the library for its high complexity and the amount of "investment" into l10n - but I'm irrelevant now and no longer present soon. Why bark? I never studied the "professional style" and if there can be something like that at all when programming in Basic. I also never studied the old "tools" module to the detail - and rarely used it.

Concerning the ways of the ScriptForge modules again: There are pros and contras, and I only investigated a tiny part of the project in its current state. The one obvious bug I experienced: An error message created by all the routines implemented for the task (including l10n of course) was detailed (many lines), but misleading (omitting the hint that a library name was missing in the name of a routine to be called - no default) when I experimented with the ExecuteBasicSript().
Anyway: The concept of reporting errors to that detail is commendable. And like the l10n tools it cannot be included with a one-in-all-solution for each specific smaller task contained in a couple of ordinary modules. It's not just "complexified", but complex by its nature.
Some bugfixing and related maintenance will surely proove the mentioned issue to only be part of the teething troubles.
A more fundamental problem may be either my rubbish-strewn system OR the loaded library (or their coincidence): I got a relevant number of crashs during the experimenting campaign. (Just this moment another one while LibO seemingly slept!) All these crashs were "incomplete": A libreoffice service persisted on the system and an unusual issue occurred during the attempt of LibO to save the current state of the loaded (crashing) document.
A part of th) background may be the fact that, while the library is loaded, LibO allocates additional memory at unforeseen times in unforeseen (all but excessive) amounts.
On Windows 10: LibreOffice 7.2 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 3121
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: ScriptForge Library (A hint concerning LibreOffice>=V7.1

Postby Lupp » Sun Mar 28, 2021 2:58 pm

Sorry! The previous post was based on my sloppy searching and insufficient checking!
The workaround I found when I started a search in the ScriptForge range of Basic modules was actually my own.
Laugh at me!!

Obsolete due to the fact that the mentioned post was deleted.
Last edited by Lupp on Sun Mar 28, 2021 10:58 pm, edited 2 times in total.
On Windows 10: LibreOffice 7.2 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 3121
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: ScriptForge Library (A hint concerning LibreOffice>=V7.1

Postby Mountaineer » Sun Mar 28, 2021 4:35 pm

More documentation is promised for LibreOffice 7.2 and parts already availabe:
https://help.libreoffice.org/7.2/en-US/ ... bPAR=BASIC

J.
OpenOffice 3.1 on Windows Vista
Mountaineer
 
Posts: 92
Joined: Sun Sep 06, 2020 8:27 am

Re: ScriptForge Library (A hint concerning LibreOffice>=V7.1

Postby Villeroy » Sun Mar 28, 2021 10:46 pm

When things require arrays, string manipulation and/or object orientation I use Python. Ventilating a language of the 90ies makes no sense. The typical VBA "programmer" won't understand what to do with this library. I've never seen any VBA library with class modules or any forum question about class modules.
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: 30116
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: ScriptForge Library (A hint concerning LibreOffice>=V7.1

Postby JeJe » Sun Mar 28, 2021 10:59 pm

Villeroy

You had me searching for the origin of Python... first released in 1991.

There was an excellent website discussing class modules in OOBasic and other things which unfortunately is deceased. Class modules are a fundamental part of the Visual Basic line of languages... though you may be right about the average Office/VBA programmer and using them... wouldn't know.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1605
Joined: Wed Mar 09, 2016 2:40 pm

Re: ScriptForge Library (A hint concerning LibreOffice>=V7.1

Postby RoryOF » Sun Mar 28, 2021 11:05 pm

For information: BASIC is an acronym for Beginners All-Purpose Symbolic Instruction Code, formulated at Dartmouth College USA about 1964.

Having learned to program in Fortran II, I could immediately program in BASIC.
Apache OpenOffice 4.1.10 on Xubuntu 20.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 32863
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: ScriptForge Library (A hint concerning LibreOffice>=V7.1

Postby JeJe » Sun Mar 28, 2021 11:07 pm

Thread on class modules:

viewtopic.php?f=21&t=58135
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1605
Joined: Wed Mar 09, 2016 2:40 pm

Re: ScriptForge Library (A hint concerning LibreOffice>=V7.1

Postby eeigor » Mon Mar 29, 2021 9:16 am

Presentation attached
File too big…
https://conference.libreoffice.org/asse ... 020-10.pdf

The authors have kindly shared tons of code with us that you can use whatever you want.
Ubuntu 18.04 LTS • LibreOffice 7.2.0.2 Community
eeigor
 
Posts: 174
Joined: Sun Apr 12, 2020 10:56 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 16 guests