ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Finding the number of lines in a block of paragraph text

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Nick Hill
Finding the number of lines in a block of paragraph text
on Mar 4, 2019 at 5:42:50 pm

I'm trying to write an expression that resizes a shape layer depending on the size of a paragraph text layer.

I could just use sourceRectAtTime() *but* if there's only one line, I want to size the box to the width of the text. If it runs over two or more lines, the box should be a fixed (maximum) width. With non-paragraph text you can just count the number of carriage returns -


L = thisComp.layer("text_layer");
tx = L.text.sourceText.valueAtTime(time);
h = tx.split('\r');
n = h.length; // how many lines we've got


But I can't think of a way to interrogate the paragraph text layer to find out how many lines it's running to. Is there one, or will this be a case of manually keyframing?



Return to posts index

Oleg Pirogov
Re: Finding the number of lines in a block of paragraph text
on Mar 5, 2019 at 1:06:43 am

The usual workaround to get the number of lines is to divide sourceRect height by line height: https://forums.creativecow.net/thread/227/40793


But since you are interested in sourceRect itself, you may duplicate your text layer and apply Animator for Character Value = 1 with Expression Selector textIndex<=4 ? 0 : 100 based on lines.

What it does is it replaces all characters in lines after [for ex.] 4th with #1 Unicode character which is not displayed in AE (in your system too, hopefully). Effectively it means that only first 4 lines are displayed with sourceRect adjusted accordingly.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]