Activity › Forums › Adobe After Effects Expressions › Text box with 2 separate text layers adapting to each other
-
Text box with 2 separate text layers adapting to each other
Posted by Sandro Maia on September 20, 2022 at 6:41 pmHello everyone.
I would like to know if it’s possible to have 2 separate text layers side by side inside a shape, with the shape adapting in size to both texts and both texts adapting to each other. I know how to make it with a single text layer but i cant warp my head around with 2 text layers.
Something like in the image and i really need it to be 2 separate text layers
Filip Vandueren replied 3 years, 7 months ago 3 Members · 8 Replies -
8 Replies
-
Filip Vandueren
September 21, 2022 at 8:09 amI get how the shape can adapt, but how do the two texts adapt to each other? Just position wise ?
-
Filip Vandueren
September 21, 2022 at 8:31 amIf all you need is the smaller text to move to the right if the name gets longer, then parent it to the first text, and give the position this expression:
margin=60;
sr=parent.sourceRectAtTime();
[sr.left+sr.width+margin,0];As for the shape layer:
add a shape layer, give it a path, give the path this expression:
margin = 60;
t1=thisComp.layer("John");
s1=t1.sourceRectAtTime();
t2=thisComp.layer("• This text layer adapts");
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);add a Fill and a Round Corners modifier.
-
Sandro Maia
September 21, 2022 at 9:57 amHi Filip, this worked perfectly. Is there also a way to keep everything centred to the composition when you type on the second text? Typing on the first text everything is aligned to the centre, but when i type on the second text the shape only expands to the right and doesn’t centre.
Thank you so much for your help! Appreciated.
-
Sandro Maia
September 21, 2022 at 11:26 amAfter trying around i’ve managed to do it with this simple expression applied to the “x” position of “John” layer.
Now everything is centred all the time.
transform.xPosition - (thisComp.layer("• This text layer adapts").sourceRectAtTime().width/2) -
Filip Vandueren
September 22, 2022 at 8:23 amSorry, forgot to get back to you.
Note that if you’ve added a margin between the layers as I did in my example, you’ll also want to add half of that margin
-
John Collucci
September 24, 2022 at 12:02 amHi Sandro & Filip, I’m in awe of these posts.
I’ve been using AE for nearly 20 years, and I use pre-saved scripts for certain common tasks, but have no real depth to how to code them myself. I feel that so much untapped capability exists for most of us.
Do you recommend any resources to actually learn the language & syntax to solve one’s own problems without relying on internet searches (& hoping someone else can help)?
-
Filip Vandueren
September 24, 2022 at 9:38 am
Reply to this Discussion! Login or Sign Up