-
Self-resizing box – multiple boxes
Hi all,
I need some guidance how to best resize multiple boxes based on text length. I am rather new to expressions, and I was wondering if someone could help out with some fairly basic automation.
In my comp I have a self-centered text and a box around it that resizes to the text length (let;s call it ‘Box1’). Box 1 has expression to get position and size based on text layer width and height.
I would like to be able to set up ‘Box 2’ which will always have a fixed width but it’s height is the same as Box1.
And finally, create a simple shape that will sit in the center of Box2.
So far I have this JS for Box1-
Size :
margin=20;
text_width = thisComp.layer(“Text”).sourceRectAtTime().width;
text_height = thisComp.layer(“Text”).sourceRectAtTime().height;
box_width = text_width + margin*2;
box_height = text_height + margin*2;
[box_width, box_height]
pos:
text_height = thisComp.layer(“Text”).sourceRectAtTime().height;
[0, text_height/2]
transform-pos:
t = thisComp.layer(“Text”);
tRect = t.sourceRectAtTime(time,false);
tUL = t.toComp([tRect.left,tRect.top]);
tLR = t.toComp([tRect.left+tRect.width,tRect.top+tRect.height]);
tCenter = (tUL + tLR)/2
myRect = sourceRectAtTime(time,false);
myUL = toComp([myRect.left,myRect.top]);
myLR = toComp([myRect.left+myRect.width,myRect.top+myRect.height]);
myCenter = (myUL + myLR)/2
delta = myCenter – tCenter;
value – delta
Any hints on how to best set up box 2 position would be greatly appreciated.