Where can I find API reference for the macro scripting in BASIC?

So, today I was playing around with the macro recorder in LibreOffice Calc. I was recording and editing macros and noticed that if change the name’s value from cell(0).Name = "ToPoint" for example to cell(0).Name = "ToShPoint" the macro below stops working:

Sub Main
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim cell(0) as new com.sun.star.beans.PropertyValue
cell(0).Name = "ToPoint"
cell(0).Value = "$B$1"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, cell)

dispatcher.executeDispatch(document, ".uno:Cut", "", 0, Array())

dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "ToPoint"
args2(0).Value = "$C$1"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())

dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
End Sub

Is the ToPoint some kind of special keyword? I was trying to find any reference to the ToPoint keyword in documentation, (specifically I checked here and here) but didn’t find anything.

Well, next to everything in programming is handled based on names. Even 123 you may interpret as the usual name of a specific number. No justification for the idea it might be different with the arguments for uno commands!

As far as I can see, the “SlotMachine” used by the recorder, and shouting commands the .uno:Something way isn’t really integrated with the API. The overview I am using (drawn into a .ods with a bit of additional functionality) is from
https://wiki.documentfoundation.org/Development/DispatchCommands#Calc_slots_.28scslots.29.
The fundamental shortcoming is the lack of a listing of usable (or mandatory) parameters defined by their names and explained concerning their functionality.
It would be a very meritorious project to create and maintain such a listing.
Currently, I think you need to analyze the source code to find the names at least.
What users actually do is based on examples created by the recorder.

What you Dim as cell(0) is badly named. It’s in fact a 1-element-collection of arguments to the .uno.GoToCell. It’s an obviously mandatory argument (but there might also be optional ones).
That you shouldn’t expect the .uno:Command system to use consistently and thoroughly designed naming is obvious from the example: What’s controlling the GoToCell command is named ToPoint. Every kind of naming in the field is a mess, imo.
(The variable giving the frame used as DispatchProvider is named document for the Basic code…
The variable for the DispatchHelper is named dispatcher …
.uno.GoToCell will also select a range if the argument named “ToPoint” is a textual range address like “B5:K13”… )

The dispatcher exists in addition to the API. If you want to learn Basic, the dispatcher is not useful. Instead use one of the guides of Andrew Pitonyak www.pitonyak.org/oo.php for example.

I don’t know a documentation of the parameters of the dispatcher outside the source code. To examine the source code use OpenGrok https://opengrok.libreoffice.org.

  1. Select core as Project
  2. Enter the uno-command without the part .uno: in the field Full Search
  3. Enter sdi in field File Path

The .sdi files are the connection between uno-command and implementation. Each uno-command has a block in such file. You can ignore the part between []. For example for changing the color of a sheet tab, you get

SfxVoidItem SetTabBgColor FID_TAB_MENU_SET_TAB_BG_COLOR
(SvxColorItem TabBgColor FID_TAB_SET_TAB_BG_COLOR)
[
]

The text between the round brackets in the second line tells you the name and data type of the parameter the uno-command needs. In this case the parameter has the name TabBgColor and the data type is a Color.

Or for your command .uno:GoToCell you will find

SfxVoidItem GoToCell SID_CURRENTCELL
(SfxStringItem ToPoint SID_CURRENTCELL)
 [
 ]

which tells you, that it has one parameter with name ToPoint and data type String.

In a recorded macro, you have the line args1(0).Name for the name of the parameter and the line args1(0).Value for its value. So yes ToPoint is a special name and not to be changed.

And to answer the question about the API: LibreOffice: Main Page

1 Like