[Solved] [Writer] How to get the current height of an item?

Creating a macro - Writing a Script - Using the API

[Solved] [Writer] How to get the current height of an item?

Postby Alectrona » Thu Mar 26, 2020 8:27 pm

myItem.height gives me the item minimal height, instead of its current height.

So if its a frame with automatic height and minimal height set to 40, myItem.height will return 400, whatever how big is the text box in reality.

Image Image
Last edited by Alectrona on Thu Mar 26, 2020 10:04 pm, edited 1 time in total.
LibreOffice 6.2.8.2 on Windows 10
Alectrona
 
Posts: 17
Joined: Tue Mar 24, 2020 7:04 pm

Re: [Writer] How to get the current height of an item?

Postby Lupp » Thu Mar 26, 2020 9:35 pm

A TextFrame and a TextBox are very different things.

Concerning a TextFrame you get the current height by
Code: Select all   Expand viewCollapse view
myTextFrame.LayoutSize.Height
.
On Windows 10: LibreOffice 6.4 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2725
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [Writer] How to get the current height of an item?

Postby JeJe » Thu Mar 26, 2020 9:36 pm

Code: Select all   Expand viewCollapse view
thiscomponent.textframes.getbyindex(0).height
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 790
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Writer] How to get the current height of an item?

Postby Alectrona » Thu Mar 26, 2020 10:50 pm

Lupp wrote:A TextFrame and a TextBox are very different things.

Concerning a TextFrame you get the current height by
Code: Select all   Expand viewCollapse view
myTextFrame.LayoutSize.Height
.


Thank you. This does give me the actual height.

JeJe wrote:
Code: Select all   Expand viewCollapse view
thiscomponent.textframes.getbyindex(0).height


This gives me the minimal height and not the current height of a frame with auto height
LibreOffice 6.2.8.2 on Windows 10
Alectrona
 
Posts: 17
Joined: Tue Mar 24, 2020 7:04 pm

Re: [Writer] How to get the current height of an item?

Postby Alectrona » Thu Mar 26, 2020 10:58 pm

However, the LayoutSize method seems to consume way more ressources

The following code, checking for a frame height every 50 milliseconds, makes LibreOffice slow down and the cursor turning into hourglass constantly

Code: Select all   Expand viewCollapse view
sub autogrow
   oDoc = thiscomponent
    oItem = oDoc.textframes.getByIndex(0)
      hgt = oItem.LayoutSize.Height
      Do
         updated_height = oItem.LayoutSize.Height
         if not (updated_height = hgt) then
            hgt = updated_height
            msgbox "Il a grandi !"
         end if
       Wait 50
      Loop Until 0=1
end sub


Any better idea to set an event listenner on a layoutSize change of a frame event?

Edit : It doesnt slow that much libreoffice but for some reason my text cursor stops blinking :(
LibreOffice 6.2.8.2 on Windows 10
Alectrona
 
Posts: 17
Joined: Tue Mar 24, 2020 7:04 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 1 guest