Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Autoscale Text Box for two lines of text

  • Autoscale Text Box for two lines of text

    Posted by Martin Brunner on November 1, 2023 at 1:39 pm

    Hi

    I am trying to build an auto scaling text box for two lines. In the image attached I have two different text boxes for each line, but now I am trying to do the same for both of them (red rectangle) but can’t get a result. For the expressions used please refer to the attached image aswell.

    Would anyone have a solution? Thanks a lot in advance!

     

    Martin

    Adam Greenberg replied 1 year, 4 months ago 2 Members · 11 Replies
  • 11 Replies
  • Martin Brunner

    November 2, 2023 at 8:56 am

    Update:

    I found the following expressions which works fine for the text box to adapt to first line of text.

    margin = 30;
    t1=thisComp.layer(“textLayer”);
    s1=t1.sourceRectAtTime();
    t2=thisComp.layer(“textLayer 2”);
    s2=t2.sourceRectAtTime();
    l = t1.toComp([s1.left, s1.top])[0] – margin;
    r = t2.toComp([s2.left+s2.width, s1.top])[0] + margin;
    t = Math.min(t1.toComp([s1.left, s1.top])[1], t2.toComp([s2.left+s2.width, s2.top])[1]) – margin;
    b = Math.max(t1.toComp([s1.left, s1.top+s1.height])[1], t2.toComp([s2.left+s2.width, s2.top+s2.height])[1]) + margin;
    createPath( [fromComp([l,t]), fromComp([r,t]), fromComp([r,b]), fromComp([l,b])], [],[], true);

    So if I am assuming correctly I would have to replace the expression for r with an expression that looks at the width of both text layers? Would anyone know how to do that? THX

  • Adam Greenberg

    November 2, 2023 at 2:05 pm

    yes, you would actually use the math expression to ask after efefcts to find the longer of the 2 and use that as the width, Ill post that expresssion shortly if someone doesnt beat me to it

  • Adam Greenberg

    November 2, 2023 at 2:25 pm

    I think you just need a new variable,

    Math.max(l,r)

    this would take the longer of l and r

  • Martin Brunner

    November 2, 2023 at 4:27 pm

    Hi Adam

    Thanks! I tried but I am not sure if I interpreted it right. I applied the Math.max to the variabale r in the last bit of the expression, which doesn’t give me a solution…

    margin = 30;
    t1=thisComp.layer(“textLayer”);
    s1=t1.sourceRectAtTime();
    t2=thisComp.layer(“textLayer 2”);
    s2=t2.sourceRectAtTime();
    l = t1.toComp([s1.left, s1.top])[0] – margin;
    r = t2.toComp([s2.left+s2.width, s1.top])[0] + margin;
    t = Math.min(t1.toComp([s1.left, s1.top])[1], t2.toComp([s2.left+s2.width, s2.top])[1]) – margin;
    b = Math.max(t1.toComp([s1.left, s1.top+s1.height])[1], t2.toComp([s2.left+s2.width, s2.top+s2.height])[1]) + margin;
    createPath( [fromComp([l,t]), fromComp([Math.max(l,r),t]), fromComp([Math.max(l,r),b]), fromComp([l,b])], [],[], true);

    Did I miss something?

  • Adam Greenberg

    November 2, 2023 at 4:52 pm

    I have a few minutes to take a look. where is this expression posted, in fact, it may be easier if you just post a reduced version of your project in here with no source files and Ill see if i can edit it to work

  • Martin Brunner

    November 2, 2023 at 4:57 pm
  • Adam Greenberg

    November 2, 2023 at 5:25 pm

    ok there you go, there might be a way to make this more efficient but i was not prepared to do all that work right now, lol. point is, it does what you want now.

  • Adam Greenberg

    November 2, 2023 at 5:26 pm

    oops . we would need to add the gap back in there, sorry about that

  • Adam Greenberg

    November 2, 2023 at 5:27 pm
  • Martin Brunner

    November 3, 2023 at 8:05 am

    Awesome! Thank you very much for your time and effort!

Page 1 of 2

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