We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.
var s = thisComp.layer("Movie Title");
var w = s.sourceRectAtTime().width;
var h = s.sourceRectAtTime().height;
var s = thisComp.layer("Movie Title");
var w = s.sourceRectAtTime().width/2;
var h = s.sourceRectAtTime().height/2;
var l = s.sourceRectAtTime().left;
var t = s.sourceRectAtTime().top;
You need to add the widths and heights to the position rather than just absolutely setting it relative to the layer/ group.
You just need to re-think the logic of this a little bit.
If the corner of the box needs to be locked to a corner of your safe area, that's what should be driving the positioning, not the text.
Box gets dimensions from text.
Text is parented to box.
Box anchor point is locked to bottom left/right corner of itself.
Box position is locked to the bottom left/right corner of safe area.
While it would certainly be possible to create one rig that does both left/right, I think it's much simpler to just make two setups, one for each side.
(I added a few static expressions just to keep the positions locked in place/avoid accidental dragging.)
Here's a rig that should work for the left, regardless of how much text you have in here. Let me know if you don't understand how to adapt it for the right side.
Thanks so much Kyle! That worked wonderfully. I was able to switch it to the right no problem.
Thank you so much for your response. I have the same problem. However I just started to work with expressions and I am struggling to adapt to the right side. Could you let me know how the script would look like?
If you want a shape layer to always conform to the text and stay lined up you must first, not mess with the anchor point of the text layer or the shape layer. You can use sourceRectAtTime() to grab the drive the size of the text box, but if you want to get the size of a text area you created you need to modify the method so that it reads sourceRectAtTime(time, true).width and sourceRectAtTime(time, true).height.
If you want to keep the shape layer lined up with the text rectangle you need to include sourceRectAtTime().left and sourceRectAtTime().top in the Rectangle position property.
Instead of parenting the shape layer to the text layer, the best option is to tie the position of the shape layer to the position of the text layer with a simple expression. At the most basic level, this is how I would set up the expressions for a resizing shape layer and keeping it always positioned properly behind the text.
// Rectangle 1> Rectangle 1 Path> Size src=thisComp.layer(index -1).sourceRectAtTime(); xPad = 10; // could be a slider yPad = 5; // could be a slider x = src.width; y = src.height; [x, y] + [xPad, yPad] //Rectangle 1> Rectangle 1 Path> Position src=thisComp.layer(index - 1).sourceRectAtTime(); x = src.width/2; y = src.height/2; t = src.top; l = src.left; [x + l, y + t] //Transform> Position src=thisComp.layer(index - 1).position;
I would use (index -1) instead of the layer name because I always want my text background layer right below the text layer.
To modify the expression so that it works on a text layer that has a text area defined you need to modify the source line to read src=thisComp.layer(Index - 1).sourceRectAtTime(time, true);
My animation presets include a checkbox to turn Extends on or off, sliders for horizontal and vertical padding, a time delay slider to adjust when the size of the text layer is sampled, and compensation for scale just in case the text layer is scaled. It also includes compensation for roundness and a slider to control roundness.
Trying to use parenting and making different presets for paragraph justification is more work than is necessary. All I have to do if I want an auto-resizing background for a text layer is double click the animation preset and a new shape layer is created that automatically fits perfectly below any text layer that has not had the Anchor Point fiddled with.