Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Is it possible to “read” the number of lines in a text box?

  • Is it possible to “read” the number of lines in a text box?

    Posted by Samuli Alapuranen on August 3, 2007 at 2:58 pm

    Could someone tell me if it would be possible to have an expression that would “read” the number of lines (or paragraphs) in a text box?

    What I’m trying to achieve is a text layer that would have 1-4 lines of text (depending on the amount of information needed) and a solid behind the layer that would adjust its height or position according to the amount of the text.

    Sam

    Samuli Alapuranen replied 18 years, 9 months ago 2 Members · 2 Replies
  • 2 Replies
  • Colin Braley

    August 3, 2007 at 4:31 pm

    Try applying this expression to the scale property of of the solid that is behind each text layer:


    //begin expression
    textLayer = thisComp.layer("A Text Layer");
    scalePerLine = 70;
    //scalePerLine is how much to increment scale by for each newline
    //--
    newLineChar = '\r';
    newLines = 0;
    for( i = 0 ; i < textLayer.text.sourceText.length; i++ ){ if( textLayer.text.sourceText.charAt( i ) == newLineChar){ newLines++; } } //-- [value[0] , value[1] + newLines * scalePerLine ] //end expression

    Just make sure textLayer refers to the right text layer. Then adjust scalePerLine until you have the desired look.

    However, there are a few problems with this expresson. First of all, whenever a new line of text is added the scale property increases linearly when in fact it should increase according to some kind of exponiential function. This is beacuse, to make a layer n pixels bigger, you can't just add n to scale. I don't have time to fix this right now, but if anyone wants to give it a try feel welcome to.

    ~Colin

    http://www.colinbraley.com

  • Samuli Alapuranen

    August 3, 2007 at 6:14 pm

    Thanks! I’ll give this a try.

    How about changing Y-position instead of Scale? It would make it easier to have exactly the same value for each line.

    Sam

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