Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Capture number of lines in Paragraph Text for expression

  • Skye Xavier

    September 15, 2024 at 7:02 pm

    I had to do a similar thing today, but I’m counting the number of lines by using carriage returns.

    Here’s the expression I used:

    const wordArray = thisComp.layer("Source Text").text.sourceText.split( '\r' );
    wordArray.length;
  • Arie Stavchansky

    September 30, 2024 at 6:26 pm

    I’ve noticed that in some fonts, like Hindi, the line count is incorrect when I use the code you provided. It works perfectly in latin based fonts, but for some reason other fonts don’t calculate it correctly. I’m not sure how to fix, but just wanted to add this note for anybody working with fonts that might have non-latin characters.

  • Andrei Popa

    October 1, 2024 at 8:33 am

    Hi Arie.

    I had the same problem with some arabic languages, while using the Noto fonts provided by google.

    I had to change the expression because the font was too high, so I subtract half of the font size from the entire height. This still counts badly if the first row consists in only characters with very small height, like “. _ ,”, but I think that case will be very rare. You can also choose at which point in time you want to calculate the number of rows. This is especially useful when you have text animators that alter the sourceRectAtTime height, so you want to put there the timestamp where your text is finished animating.

    //L=layer, T=time
    function getNumRows(L, T) {
    var H = L.sourceRectAtTime(L.sourceTime(T), false).height;
    var myStyle = L.text.sourceText.style;
    myFontSize = myStyle.fontSize;
    myLeading = myStyle.autoLeading ? myFontSize * 1.2 : myStyle.leading;
    return Math.ceil((H - myFontSize * 0.5) / myLeading);
    }
    getNumRows(thisLayer, 0)


    Andrei

Page 2 of 2

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy