Forums › Adobe After Effects Expressions › How can I modify this expression to make it work with multiple text layers
How can I modify this expression to make it work with multiple text layers
Finn Hitchcock
November 16, 2019 at 9:26 pmHi,
I’ve got this expression which I use to auto size a rectangle to the size and letters of the text. I have been trying to modify/create an expression which does this, with 2 text layers.
(I’m putting the expression in rectangle size)
Expression:
L=thisComp.layer(“text”);
X=L.sourceRectAtTime().width;
Y=L.sourceRectAtTime().height;
[X,Y]Thanks in advance for help!
F 🙂
L=thisComp.layer("text");
X=L.sourceRectAtTime().width;
Y=L.sourceRectAtTime().height;
[X,Y]Dan Ebberts
November 16, 2019 at 10:31 pmThis is a kind of general solution, but it should do what you’re looking for:
L1 = thisComp.layer(“text 1”);
r1 = L1.sourceRectAtTime();
ul1 = L1.toComp([r1.left,r1.top]);
lr1 = L1.toComp([r1.left+r1.width,r1.top+r1.height]);
L2 = thisComp.layer(“text 2”);
r2 = L2.sourceRectAtTime();
ul2 = L2.toComp([r2.left,r2.top]);
lr2 = L2.toComp([r2.left+r2.width,r2.top+r2.height]);
ulTot = [Math.min(ul1[0],ul2[0]),Math.min(ul1[1],ul2[1])];
lrTot = [Math.max(lr1[0],lr2[0]),Math.max(lr1[1],lr2[1])];
lrTot – ulTotDan
Log in to reply.