Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Make a Text Box Resize to the Longer of 2 Text Layers

  • Make a Text Box Resize to the Longer of 2 Text Layers

    Posted by Al Edwards on October 31, 2019 at 3:10 pm

    Hello creative community!

    I am trying to make an editable lower third with 2 lines of text that are different colors/fonts/sizes, and a text box that resizes to the longer of the 2 lines.

    Attempt 1:
    I thought I had accomplished this by having both lines of text in a single text layer, and an expression on the text box’s size (code is pasted below). It worked swimmingly. However, when I took my AE composition into Premiere and changed the text (under effects controls), suddenly the text in the second line was the same color/font/size as the top line.

    Attempt 2:
    I tried solving this by separating my 2 lines of text into 2 text layers, then I hard-coded the height of the text box (85). But I still don’t know how to make the text box width resize correctly. Sometimes the talent’s name is longer, sometimes their title is longer, so I need the text box to be as wide as the widest line of text.

    So my question is:
    Can I make one layer look at 2 other layers and match whichever one is wider? Would this involve an else/if expression? Thanks in advance!

    m = 30
    myText = thisComp.layer("Text").sourceRectAtTime();
    myTextWidth = myText.width + m;
    myTextHeight = myText.height + m;

    [myTextWidth, myTextHeight]; // Note: in Attempt 2, I hard-coded 85 instead of using myTextHeight

    Al Edwards replied 6 years, 10 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    October 31, 2019 at 5:40 pm

    This is how you would use the wider layer:

    myText = thisComp.layer(“Text”).sourceRectAtTime();
    myText2 = thisComp.layer(“Text 2”).sourceRectAtTime();
    myTextWidth = Math.max(myText.width,myText2.width) + m;

    Dan

  • Al Edwards

    November 1, 2019 at 1:55 pm

    Wonderful! It works as advertised. Thanks for your quick reply, Dan.

    Al

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