Number of line breaks in shape

Problem:
Hi, I want to use variable boxes for variable texts. The height of the boxes should depend on the number of lines that the text breaks into in that given box. Is there a way to determine the number of lines that a text is broken up into?
E.g:
Text “Hello world! Hello world!”
would appear in a wide box as one line:
Hello world! Hello world!
In a narrow box it would be four lines:
Hello
world!
Hello
world!
Is it possible to get the number of lines?
Thanks, Rolf

ActivePresenter version:

OS:

Notes:

Hi Rolf,

Though it’s not officially supported, but you can use the following script to fit the shape to the text:

var longText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
var object = prez.object('Shape_1');
// change object text
object.text(longText);
// get text size
var textMargin = object.textMargin(); // [left, top, right, bottom]
var textWidth = object.textNode.offsetWidth + textMargin[0] + textMargin[2];
var textHeight = object.textNode.offsetHeight + textMargin[1] + textMargin[3];
// adjust object size to fit new text
var objectSize = object.shape.shapeSizeForText(textWidth, textHeight);
object.size(objectSize[0], objectSize[1]);

Regards

Thanks, Toan,
excellent support - as always!!!
Best, Rolf

1 Like