Adobe After Effects Expressions Forum
How do I make this rectangle stay put when it resizes?
How do I make this rectangle stay put when it resizes?
by Al Edwards on Jun 8, 2020 at 3:47:51 pm

Hey all! I'm scratching my head over how to solve this. I have a rectangle that automatically resizes to 2 lines of left-aligned text. I'm adapting it to include space for a logo to the left of the text.

I figured out how to resize the width correctly, but I'm having trouble with the position. The effect I'm trying to get is to have only the right side of the rectangle grow or shrink to fit the text. I have an expression on the rectangle's position, but I can't figure out why the rectangle scoots to the right as the text gets longer. (Screenshots attached)

Any suggestions? Thanks in advance!

-Al




t = thisComp.layer("Text").sourceRectAtTime();
t2 = thisComp.layer("Text 2").sourceRectAtTime();
logo = thisComp.layer("Logo").sourceRectAtTime();
w = Math.max(t.width, t2.width) + logo.width / 2;
h = t2.height / 2;
l = t2.left;
top = t2.top;

[w + l + logo.width, h + top];



Re: How do I make this rectangle stay put when it resizes?
by Al Edwards on Jun 8, 2020 at 4:07:20 pm

Oh duh, I just figured it out... I messed up the order-of-operations on the width calculation.

Here's the corrected code in case it helps someone else!

-Al

t = thisComp.layer("Text").sourceRectAtTime();
t2 = thisComp.layer("Text 2").sourceRectAtTime();
logo = thisComp.layer("Logo").sourceRectAtTime();
w = Math.max(t.width, t2.width) / 2 + logo.width;
h = t2.height / 2;
l = t2.left;
top = t2.top;

[w + l + logo.width, h + top]; // Keeps rectangle aligned left






© CreativeCOW.net