Page 1 of 1

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

PostPosted: Sun Mar 28, 2021 2:47 am
by Lupp
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.

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

PostPosted: Sun Mar 28, 2021 12:30 pm
by JeJe

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

PostPosted: Sun Mar 28, 2021 12:51 pm
by eeigor
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
<...>

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

PostPosted: Sun Mar 28, 2021 12:54 pm
by JeJe

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/

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

PostPosted: Sun Mar 28, 2021 1:25 pm
by JeJe
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.

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

PostPosted: Sun Mar 28, 2021 2:00 pm
by eeigor
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.

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

PostPosted: Sun Mar 28, 2021 2:46 pm
by Lupp
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.

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

PostPosted: Sun Mar 28, 2021 2:58 pm
by Lupp
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.

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

PostPosted: Sun Mar 28, 2021 4:35 pm
by Mountaineer
More documentation is promised for LibreOffice 7.2 and parts already availabe:
https://help.libreoffice.org/7.2/en-US/ ... bPAR=BASIC

J.

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

PostPosted: Sun Mar 28, 2021 10:46 pm
by Villeroy
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.

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

PostPosted: Sun Mar 28, 2021 10:59 pm
by JeJe
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.

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

PostPosted: Sun Mar 28, 2021 11:05 pm
by RoryOF
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.

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

PostPosted: Sun Mar 28, 2021 11:07 pm
by JeJe
Thread on class modules:

viewtopic.php?f=21&t=58135

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

PostPosted: Mon Mar 29, 2021 9:16 am
by eeigor
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.