Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression that recognises 2 lines of text

  • Expression that recognises 2 lines of text

    Posted by Deanna Keogh on March 14, 2019 at 5:55 am

    Hi,

    Im trying to create a text box, using sourceReactAtTime that follows my text based on how many characters and lines there are. I’ve used this tutorial: https://www.youtube.com/watch?v=CVliDoNgoCg
    Which is very helpful but seeing as my expression knowledge isn’t vast I’m not sure how to word my code to allow the shape layer to clip to line one and use possibly another to clip to line two.

    What I have:

    Vs

    What I want it to look like:

    I hope that this makes sense.
    These are the expressions that I am using that Ive gotten from the tutorial

    var s = thisComp.layer("Subtitles");
    var w = s.sourceRectAtTime().width/2;
    var h = s.sourceRectAtTime().height/2;
    var l = s.sourceRectAtTime().left;
    var t = s.sourceRectAtTime().top;

    [w+l,h+t]

    Some contents or functionalities here are not available due to your cookie preferences!

    This happens because the functionality/content marked as “Google Youtube” uses cookies that you choosed to keep disabled. In order to view this content or use this functionality, please enable cookies: click here to open your cookie preferences.

    Jean Simenon replied 6 years, 2 months ago 5 Members · 10 Replies
  • 10 Replies
  • Scott Mcgee

    March 14, 2019 at 4:40 pm

    As far as I’m aware the answer is no.

    There’s a bit of a cheat around this.

    You need a master text layer that’ll be hidden. This is where you will type your text.

    Then you’ll have 2 text layers. Line 1 and Line 2. You then link the text to your master text layer and split them.

    So
    Line 1
    text.sourceText.split(‘\r’)[0];

    Line 2
    text.sourceText.split(‘\r’)[1];

    Then create two shape layers to fit around these two text layers.

  • Tomas Bumbulevičius

    March 14, 2019 at 5:34 pm

    This solution should solve your issue 100%. Apply your text to the layer visible at the center and make corrections in the ‘control’ null effects. This will place text from the bottom center and will grow upwards.

    There is also a delay applied, so just remove it from shape layers if not needed.

    If any questions occurs – just let me know, haven’t used it for a while, but its solely my developed solution for such purposes. A bit too complex and slow, but it helped me a lot.

    13203_textboxes1to4lines.aep.zip

    Find out more:
    After Effects Tutorials: motion design, expressions, scripting.

  • Deanna Keogh

    March 15, 2019 at 12:10 am

    Thanks so much for that.

    I went to check out your project but unfortunately Im running an older AE and cant upgrade that this stage.
    Any chance you could make that file backwards compatible please?
    You’re a gem!

  • Deanna Keogh

    March 15, 2019 at 12:23 am

    Thanks for your response!

    So basically create 2 seperate layers of text that references to a text guide layer ?
    And then have 2 seperate shape layers?

    If that is the case I might as well just type straight into 2 seperate text layers and have the shape layer around them, without having the guide. Either way both of these solutions are fine. I suspected as much. I just didn’t know if an expression existed where it would split the text and subsequently the shape layer it like I wanted.

    Thanks so much!

  • Tomas Bumbulevičius

    March 15, 2019 at 6:35 am

    Deanna,

    below is compatible since CC14. Hope that helps.

    13206_textboxes1to4linescc14.zip

    Find out more:
    After Effects Tutorials: motion design, expressions, scripting.

  • Scott Mcgee

    March 15, 2019 at 9:51 am

    That’s a cool project you have set up. I’m not even gonna pretend that I completely understand your expression for line breaking. I get the gist, but that is some serious expressioning haha.

  • Tomas Bumbulevičius

    March 15, 2019 at 2:52 pm

    Thanks Scott. Indeed, I am pretty sure there could be easier way of doing it, and more neat, but once I reached a point where it generated good enough results, I just added few extra checks ‘here’ and ‘there’ to avoid exceptions.

    Find out more:
    After Effects Tutorials: motion design, expressions, scripting.

  • Ahmed Raad

    December 18, 2019 at 10:54 pm

    Hi everyone

    Tomas I’ve download the project that you put, but it did’t working because I use windows, so if you could write the script that you did and I will be grateful to you.

    sorry for my language i typing English with french grammar haha

  • Jean Simenon

    March 20, 2020 at 6:10 pm

    Wow. Thanks for all the hard work Tom on this.

    I personally wanted to get the boxes to expand from the LEFT side of the text all the way to the RIGHT (instead of expanding from the middle as it is right now), so I made the following changes:

  • In the SHAPE layers named 1, 2, 3, 4, under TRANSFORM, the Anchor Point expression used to be:
  • R = thisLayer.sourceRectAtTime(time);
    T = R.top;
    L = R.left;
    W = R.width;
    H = R.height;
    ([L+W/2,T])

  • Now I changed it simply to:
  • R = thisLayer.sourceRectAtTime(time);
    T = R.top;
    L = R.left;
    W = R.width;
    H = R.height;
    ([L,T])

  • And, under TRANSFORM, I also changed the Position expression from this:
  • yPos = 0 + thisComp.layer('control').effect('box-yPos')('Slider');
    xPos = thisComp.width / 2 + thisComp.layer('control').effect('box-xPos')('Slider');
    [xPos, yPos]

  • To this:
  • R = thisLayer.sourceRectAtTime(time);
    W = R.width;

    yPos = 0 + thisComp.layer('control').effect('box-yPos')('Slider');
    xPos = thisComp.width / 2 + thisComp.layer('control').effect('box-xPos')('Slider');
    [xPos-W/2, yPos]

    —-
    Not hollywood. Never.

  • Jean Simenon

    March 20, 2020 at 6:13 pm

    Sorry I tried to highlight the code, but it came out as . Pardon me for that.

    —-
    Not hollywood. Never.

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