Accessing Push Button or Text Box or LabelField with code

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
hosta
Posts: 2
Joined: Sat Mar 28, 2020 7:27 pm

Accessing Push Button or Text Box or LabelField with code

Post by hosta »

Hello,

I have a problem to establish control within Macro for Push Button, Text Box and Label Field which are not a part of Dialog, but they are lying on a Draw Page.
There is a lot of tutorials of accessing Controls within Dialog or Forms.

Code: Select all

	
Sub transferTextFromTextBox   
   Dim oDoc as Object
   Dim oPage as Object
   Dim oTextBox as Object
REM set oDoc object variable to the current document 
   oDoc = ThisComponent
REM set oPage  object variable to the current page
   oPage = oDoc.getDrawPages().getByIndex(0)
REM Get text from TextBoxTITLE
   oTextBox = oPage.getByName("TextBoxTITLE")
REM Show MSGBOX
   MsgBox (MasterTitle,0,"TITLE TextBox")
End Sub
There is error when code stop at oTextBox

Please Help
OpenOffice 4.1.7 on MacOS 10.15.4
JeJe
Volunteer
Posts: 2777
Joined: Wed Mar 09, 2016 2:40 pm

Re: Accessing Push Button or Text Box or LabelField with cod

Post by JeJe »

There isn't a getbyname method, only getbyindex. If you use MRI, you can find this out easily. You'll have to loop through every index to find the one with the chosen name.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
hosta
Posts: 2
Joined: Sat Mar 28, 2020 7:27 pm

Re: Accessing Push Button or Text Box or LabelField with cod

Post by hosta »

Thanx for hint.
I will try.
Report follows...
OpenOffice 4.1.7 on MacOS 10.15.4
User avatar
Sébastien C
Posts: 111
Joined: Mon Jan 04, 2010 5:06 pm
Location: Meymac, France

Re: Accessing Push Button or Text Box or LabelField with cod

Post by Sébastien C »

A function “findObjectByName” is available in the book (in French) « Programmation OpenOffice.org et LibreOffice » by Bernard Marcelly and Laurent Godard, Eyrolle editor.

The editor offers, in free reading, the appendix where, precisely, it is located. This is page 24/695 of this PDF.
« Rechercher un objet par son nom », so: “Search for an object by name

If you do not understand (at all) French, I will translate this passage in this thread for you. If not, that should help you a little…
:D
 Edit: I am not at all sure that the service com.sun.star.drawing.Shape3DScene described in table B-1 of the PDF still exists... On the other hand, the PDF (of this version of the book) does not speak of a service which corresponds precisely to your request... It is : com.sun.star.drawing.ControlShape 
LibreOffice v. 7.3.2.2, under GNU-Linux Mint and, in virtualization and just for tests, LibreOffice v. 7.3.2.2 an OpenOffice v. 4.1.12 under M$-W 10 :ouch: .
Post Reply