Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Text Box Constraints

  • Text Box Constraints

    Posted by Jon Toogood on November 8, 2023 at 3:06 pm

    Hi, expression geniuses!

    I’m a veteran AE user, but have never been able to get my head around expressions, and have been scratching my head, over what I think should be quite a simple fix, but I’m just too stupid! If anyone could help, I’d be extremely grateful. I need to create a rounded text box, which will become a MOGRT, which grows with the amount of text in the paragraph. The box needs to have a series of parameters: It needs to be locked at the top left, so it doesn’t move or grow upwards; It needs to have a fixed width (eg 400 pixels) and a minimum height of 200 pixels: It needs to grow downwards with the amount of text input, and I need to have control over the amount of pixels of margin I have between the text and the box.

    So far, I have these parameters, which do everything I need, apart from fixing the width to 400 pixels and stopping the box from going below 200 pixels in height:

     

    Rectangle Path:

    margin = 31;

    text_width = thisComp.layer(“Text”).sourceRectAtTime().width;

    text_height = thisComp.layer(“Text”).sourceRectAtTime().height;

    box_width = text_width + margin*2;

    box_height = text_height + margin*2;

    [box_width, box_height]

     

    Rectangle Position:

    text_height = thisComp.layer(“Text”).sourceRectAtTime().height;

    [0, text_height/2]

     

    Transform:Rectangle Position:

    t = thisComp.layer(“Text”);

    tRect = t.sourceRectAtTime(time,false);

    tUL = t.toComp([tRect.left,tRect.top]);

    tLR = t.toComp([tRect.left+tRect.width,tRect.top+tRect.height]);

    tCenter = (tUL + tLR)/2

    myRect = sourceRectAtTime(time,false);

    myUL = toComp([myRect.left,myRect.top]);

    myLR = toComp([myRect.left+myRect.width,myRect.top+myRect.height]);

    myCenter = (myUL + myLR)/2

    delta = myCenter – tCenter;

    value – delta

     

    As I said earlier, if anyone could help me out, I’d be very grateful.

    Brie Clayton replied 8 months, 2 weeks ago 3 Members · 7 Replies
  • 7 Replies
  • Adam Greenberg

    November 8, 2023 at 6:04 pm

    I have some free time, do you have a project you can share with us and one of us can post it back with the changes.

    But, if the box is maximum 400 by 200, How would you like the text to behave if the paragraph gets too long. or is that not an issue.

  • Jon Toogood

    November 9, 2023 at 8:46 am

    Hi Adam,

    Thank you so much for getting back to me & for taking a look. I’ve attached a project for you, and hopefully you’ll quickly see the issue. As a quick overview, the majority of the text boxes will have 2 lines of text (I’ve looked again at the size of the outer box, and it needs to be 700×140, not 400×200) So this is the default size. Occasionally, it will have just one word (which is why I need the minimum constraints, so the box stays the same size as when there are 2 lines) but we are able to scale the box on the Y axis for 3 or more lines (as you’ll see in the project) Basically, everything is fine for 2 or more lines – I just need to stop the box shrinking when its less than that. I hope that makes sense? There is also an orange marker which scales with the box.

    Many thanks again, Adam, it’s much appreciated.

  • Adam Greenberg

    November 9, 2023 at 3:11 pm

    ok i got you 2/3`s of the way there. the code for the rectangle position I have never seen before so I am unable to edit the code on the rectangle position. But the good news is, the logic is simple.

    The value just needs to be clamped, so basically you tell after effects the minimum and maximum size.

    so i added that code to the position property and the size property.

    here is an updated project, so we are very close. someone in here might ring in and fix it if you are unable to do it yourself. But it is 100% doable. but i cant figure out why the rectangle property does not have 2 dimensions in the code. it might be easier to rewrite the whole code from scratch to avoid this property that i cant seem to understand. I have similar projects and the code is simpler than this, Ill see if I can find something that does the same thing for you if someone doesnt ring in soon.

  • Adam Greenberg

    November 9, 2023 at 3:37 pm

    here is something maybe you can copy in your project. it does what you talked about. it takes the size of the paragraph text but keeps a minimum of 140. the other shape does the same thing but with a fixed width.

  • Jon Toogood

    November 9, 2023 at 4:27 pm

    That’s fantastic, thanks so much for your help Adam – I’ll download those now and take a look.

    Many thanks

  • Jon Toogood

    November 9, 2023 at 4:42 pm

    I really appreciate your help, Adam – I’ve just had a look at what you’ve done, and I think between both projects, I’ll be able to get the desired effect. Expressions are like a dark art to me, so I’m very grateful for your time and expertise. Thank you

  • Brie Clayton

    November 9, 2023 at 6:23 pm

    Thank you for solving this, Adam!

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