Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Get number of wrapped lines from some paragraph text

  • Get number of wrapped lines from some paragraph text

    Posted by Paul Roper on November 22, 2013 at 3:18 pm

    Hello,
    I have used the expression (below – which I think I got from this site, from one of the expression geniuses) to get the number of lines in a chunk of text by counting the number of “newline” characters ( \r on Mac OS X). But if I have a chunk of paragraph text, with wrapped lines, this will not work. I’ve tried using \n instead, which I’ve read is the “newer” carriage return character for Mac OS X but this always just returns “1” regardless of the text.

    I’m trying to align a shape layer’s y-position with each new line – similar to bullet points:

    • This is the first bullet of text.
    • This is the second. The bullets always stay with the first line regardless of how much the chunk of text has wrapped, even if it goes over several lines.
    • And more text….

    Any suggestions, anyone?

    Thanks,

    Paul

    textLayer = thisComp.layer("body text");
    newLineChar = "r";
    newLines = 0;
    for( i = 0 ;
    i < textLayer.text.sourceText.length; i++ )
    {
    if( textLayer.text.sourceText.charAt( i ) == newLineChar)
    {
    newLines++;
    }
    }
    newLines+1

    Kevin Camp replied 12 years, 10 months ago 2 Members · 1 Reply
  • 1 Reply
  • Kevin Camp

    November 22, 2013 at 7:25 pm

    i’ve never found a way, maybe some one can give a definitive answer… so i’ll stop trying to do this 😉

    i know ae knows how many lines are in a text paragraph layer, because if you do add text animator to a paragraph text layer that has wrapping lines, twirl down the advanced tab, set ‘based on’ to lines and ‘units’ to index, low-and-behold the end point changes to the number of lines in the text layer.

    **before you get to excited, thinking that you can just link you expression to the end point value of that text layer (as i did once), that end point value doesn’t update with a source text update.. so if the first time you try this the end point value is ‘3’, it will remain 3 despite how many times lines are in there the next time you type (or copy/paste).

    Kevin Camp
    Senior Designer
    KCPQ, KMYQ & KRCW

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