BASIC example - get information about a selected shape on LibreOffice Draw

I’m trying to use LibreOffice BASIC to link data from a LibreOffice Base database, with shapes on a LibreOffice Draw document. I’ve made some progress accessing the data, but need to understand how I can determine which shape has been selected in the Draw document, then read some properties of that shape. I will then use the shape property to build a SQL statement to get the right data from the Base file. I’m finding this a very steep learning curve and though there is some useful information around, there is nothing I have found (yet) that shows me how to get the selected shape and read properties of it.

Any assistance (preferably and example Sub) would be greatly appreciated.


Shapes are kept on the DrawPage. You can access the selected item(s) by index and obtain the name and other information you are looking for. There can be multiple indexed items if more than one was selected. Example:

Sub Snippet2
  Dim oCurrentSelection As Variant
  Dim oObj1 As Variant
  oCurrentSelection = ThisComponent.getCurrentSelection()
  oObj1 = oCurrentSelection.getByIndex(0)
  MsgBox oObj1.Name
End Sub

You can find out how many items were selected by checking the count:

  nCount = oCurrentSelection.getCount()


You can further examine the object using a tool such as Mri. Links for this can be found in my answer on this post → How to Get and Put data from/to form fields with a macro

You may want to look at Open Office Macros Explained by Andrew Pitonyak. PDF here → OOME

Thanks @Ratslinger - that’s the information I need. I have downloaded Andrew Pitonyak’s resource along with a couple of others. They all have good information, but finding what I’m looking for is proving to be my biggest challenge. Easy enough to do a search - once you know the correct word to search for.