ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

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

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Al Edwards
Make a Text Box Resize to the Longer of 2 Text Layers
on Oct 31, 2019 at 3:10:02 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


Return to posts index

Dan Ebberts
Re: Make a Text Box Resize to the Longer of 2 Text Layers
on Oct 31, 2019 at 5:40:46 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



Return to posts index

Al Edwards
Re: Make a Text Box Resize to the Longer of 2 Text Layers
on Nov 1, 2019 at 1:55:38 pm

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

Al


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]