I have been unable to find the required method to select a specific Shape or to select all Shapes on a draw page.
Newbie at LO Basic (good at VBA).
Any help would be appreciated
KevinR
LibreOffice 7, Windows 10 x64
I have been unable to find the required method to select a specific Shape or to select all Shapes on a draw page.
Newbie at LO Basic (good at VBA).
Any help would be appreciated
KevinR
LibreOffice 7, Windows 10 x64
It is absolutely necessary to “select” the shape (to mark it graphically) or it is enough just to “get” it with the macro code? What do you want to achieve really?
The “LO Basic” (StarBasic) is a really simple programming language. But you need to study the thousands of the API functions, what you must call from a supported programming language. (API: Application Programming Interface)
Select one:
oController = ThisComponent.getCurrentController()
oDrawPage = ThisComponent.getDrawPages().getByIndex(0)
oShape = oDrawPage.getByIndex(0)
oController.select(oShape)
Select all:
oFrame = ThisComponent.getCurrentController().Frame
oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
oDispatcher.executeDispatch(oFrame, ".uno:SelectAll", "", 0, Array())
Hi Zizi64, JimK,
Thank you both for your rapid replies.
Firstly, I agree that I need to study the API functions. From what I have investigated so far It’s a bit of a minefield, any pointers on which documents I should start with to grasp the context?
Second,
The two routines provided both worked well - Thank You.
They show me that I need to focus on the API in particular as I need to learn the syntax etc.
KevinR - LibreOffice 7, Windows 10 x64
My first tip: Download, install and use one of the excellent and free Object inspection tools like the MRI or the XrayTool. These tool can list the properties and the methods 8and many other things) of the programming objects (Like the objects in the Jim K’s sample code below named “oController”, “oDraw”, “oShape”, “oFrame”, “oDispatcher”, etc…
https://berma.pagesperso-orange.fr/index2.html
My second tip:
Download and study Andrew Pitonyak’s excellent (and free) macro programming books:
@KevinR: This is not a kind of forum as you may know it, but a Q&A site.
Therefore you should not use the option ‘Add Answer’ for a post like you intended it here. Answers are expected to answer the original question. To answer on somebodie’s answer or on a comment, use the tool ‘add a comment’.
@Zizi64: I have installed Xray and getting used to what it provides. Tried installing MRi but it failed, will try again. I have also downloaded and started reading a copy of Andrew’s book - it’s very good and will keep me going for a while. Many thanks for the tips.
@Lupp: re your comments on the API. This is really useful stuff. I have investigated the LibreOffice 6.4 SDK API Reference as you suggested. Lots to read and I am dissecting some example routines to get me started. Thank You.
"I have installed Xray and getting used to what it provides. Tried installing MRi but it failed, " In my opinion, one of the Object Inspection Tools will enough for you.
Without the DispatchHelper:
The relevant API service in Draw
is com.sun.star.drawing.ShapeCollection
.
In Basic you can get an instance by myNameForIt = CreateUnoService("com.sun.star.drawing.ShapeCollection")
.
The new instance is initially empty (.Count = 0
). You can add any already existing shape (say myNextTargetShape
) by myNameForIt.add(myNextTargetShape)
. There also is the respective .remove
method.
An object supporting the mentioned service can be selected using myDrawingDocument.CurrentController.select(myNameForIt)
, but if the collection contains objects from more than one DrawPage
, selecting it will be refused without throwing an error.
Any DrawPage
of a Draw
document supports the needed service itself, and can therefore be passed to the .select()
method. In addition the .DrawPage
of any sheet of a SpreadsheetDocument
or the one .DrawPage
of a TextDocument
can be selected with the effect of “select them all”. Not reducing the topic to Draw
, you need to know that also FormControl
and Chart
objects are hosted by shapes, and will therefore be selected in the mentioned way.
Quoting @KevinR: “Newbie at LO Basic (good at VBA).”
Don’t ecpect programming for LibreOffice to be similar to doing it with any VBA.
Coming from the given topic you may start with checking LibreOffice: ShapeCollection Service Reference to learn what I mean.
In LibreOffice it’s not Basic itself (or any other usable programming language) what provides the relevant means, but the API.