[Solved] Writer: Getting a frame details

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
pjarocki
Posts: 5
Joined: Thu Nov 17, 2022 10:53 am

[Solved] Writer: Getting a frame details

Post by pjarocki »

I wanted to use a XDrawPageSupplier to see if I can get a frame details, but that interface is deprecated. There is no information which interface should be used.
I was trying to use XTextShapesSupplier, but it is always empty.

Below is a sample code:

Code: Select all

css::uno::Reference<css::lang::XMultiComponentFactory> xServiceManager = mxContext->getServiceManager();
            
css::uno::Reference<css::frame::XDesktop> xDesktop(xServiceManager->createInstanceWithContext("com.sun.star.frame.Desktop", mxContext), css::uno::UNO_QUERY);
if (!xDesktop.is())
	return;

css::uno::Reference<css::lang::XComponent> xComponent = xDesktop->getCurrentComponent();
if (!xComponent.is())
	return;
	
css::uno::Reference<css::text::XTextShapesSupplier> xTextShapesSupplier(xComponent, css::uno::UNO_QUERY); //xTextShapesSupplier is empty
How I can get a frame details?
Below is a sample file. I want to get details about top and bottom frame.
example.odt
(10.19 KiB) Downloaded 58 times
Last edited by pjarocki on Fri Nov 18, 2022 4:59 pm, edited 2 times in total.
LibreOffice 7.4 on Windows 10
JeJe
Volunteer
Posts: 2787
Joined: Wed Mar 09, 2016 2:40 pm

Re: Writer: Getting a frame details

Post by JeJe »

In Basic its thiscomponent.textframes

Code: Select all

msgbox thiscomponent.textframes.getbyindex(0).string 
Result is "top"

Do you use MRI?

https://extensions.openoffice.org/en/pr ... ction-tool
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
pjarocki
Posts: 5
Joined: Thu Nov 17, 2022 10:53 am

Re: Writer: Getting a frame details

Post by pjarocki »

JeJe wrote: Thu Nov 17, 2022 1:34 pm In Basic its thiscomponent.textframes

Code: Select all

msgbox thiscomponent.textframes.getbyindex(0).string 
Result is "top"

Do you use MRI?

https://extensions.openoffice.org/en/pr ... ction-tool
Thank you, it works, but only when text frames have been created in LibreOffice. The example document was created in Microsoft Word and saved as odt file. In c++, hasElements() on a getTextFrames() returns true, but when you use getElementNames() on a getTextFrames(), the list will be empty (only when document was created in Microsoft Word).
I was hoping it would work fine for both applications.

I don't use MRI, because MRI doesn't support newer versions of LibreOffice. I saw in the link that newer versions of OpenOffice are supported, so I will install OpenOffice and MRI.
LibreOffice 7.4 on Windows 10
JeJe
Volunteer
Posts: 2787
Joined: Wed Mar 09, 2016 2:40 pm

Re: Writer: Getting a frame details

Post by JeJe »

This works for me (OOBasic) on LibreOffice 7.4 on Windows 10 with your sample document.

Code: Select all

a= thiscomponent.textframes.getelementnames(0)
msgbox a(0)
MRI 1.3.3 - the first one on that page - runs fine for me on it too.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
pjarocki
Posts: 5
Joined: Thu Nov 17, 2022 10:53 am

Re: Writer: Getting a frame details

Post by pjarocki »

JeJe wrote: Thu Nov 17, 2022 6:58 pm This works for me (OOBasic) on LibreOffice 7.4 on Windows 10 with your sample document.

Code: Select all

a= thiscomponent.textframes.getelementnames(0)
msgbox a(0)
MRI 1.3.3 - the first one on that page - runs fine for me on it too.
Today I installed OpenOffice and MRI tool, both works fine.
My sample document was modified before being attached on forum. I changed text in header, footer and removed watermark. Doing this fixes that getTextFrames function returns empty list. On my others document which was created from Microsoft Office, getTextFrames returns empty list.
Using MRI, I found that getDrawPages returns all objects I need to get frame details, even for those "broken" files.

Problem solved for me. Thank you for your help.
LibreOffice 7.4 on Windows 10
Post Reply