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

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

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

Post 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.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

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

Post by JeJe »

OT but I noticed this the other day

https://blog.documentfoundation.org/blo ... code-2021/
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
eeigor
Posts: 214
Joined: Sun Apr 12, 2020 10:56 pm

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

Post by eeigor »

1. ScriptForge Dictionary vs com.sun.star.container.EnumerableMap (??)
2. Is it worth cluttering libraries with such primitive procedures?

Code: Select all

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

   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

	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.5.3.2 Community
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

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

Post 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/
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

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

Post 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.
Last edited by JeJe on Sun Mar 28, 2021 2:04 pm, edited 1 time in total.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
eeigor
Posts: 214
Joined: Sun Apr 12, 2020 10:56 pm

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

Post 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.
Ubuntu 18.04 LTS • LibreOffice 7.5.3.2 Community
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

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

Post 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.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

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

Post 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.
Last edited by Lupp on Sun Mar 28, 2021 10:58 pm, edited 2 times in total.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
Mountaineer
Posts: 310
Joined: Sun Sep 06, 2020 8:27 am

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

Post 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.
OpenOffice 3.1 on Windows Vista
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Post 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.
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
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

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

Post 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.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

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

Post 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.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

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

Post by JeJe »

Thread on class modules:

viewtopic.php?f=21&t=58135
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
eeigor
Posts: 214
Joined: Sun Apr 12, 2020 10:56 pm

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

Post 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.
Ubuntu 18.04 LTS • LibreOffice 7.5.3.2 Community
Post Reply