Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Expression- getting each text height when there are 3 line text in the text box

  • Expression- getting each text height when there are 3 line text in the text box

  • Aurora Wang

    January 30, 2023 at 6:48 pm

    I am looking for an expression that can get each line text’s height when there are several lines in the text box. It would be very useful if I create a responsive mask box for each line.

  • Julian Chojnacki

    January 30, 2023 at 7:39 pm

    Hi, you could either take fontSize*.75 + leading, or the sourceRect height of your text layer divided by the number of lines. So:

    const { fontSize, leading } = thisComp.layer("Text");

    const lineHeight = fontSize*.75 + leading;


    const numLines = thisComp.layer("Text").text.sourceText.split('\r').length;

    const lineHeight = thisComp.layer("Text").sourceRectAtTime().height/numLines;

  • Aurora Wang

    January 30, 2023 at 8:56 pm

    Hey Julian, Thank you for your expression!

    – The first one doesn’t work if I change the text from 3 lines to 2 lines. (Attached the images) Please lmk if I am wrong.

    – The second one works great! If you have time, would you please explain the “const numLines thisComp.layer(“Text”).text.sourceText.split(‘\r’).length;” a little bit?

    I only know that using “split(‘\r’)” can return the text to the next line. And “length” in text expression is the length of all characters. I have no idea when you combine them, you will get the number of lines. Wow!

  • Julian Chojnacki

    February 5, 2023 at 2:10 pm

    Hi Aurora, you’re right – the first code needs tweaking. Check out this great reference that dives a bit deeper into getting actual text heights:

    Regarding split(‘\r’).length, split first breaks up the text into an array using the carriage return as a separator, then length returns the length of that array.

Viewing 1 - 4 of 4 posts

Log in to reply.

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