Copy link to clipboard
Copied
Trying to write an expression that automatically pushes a shape/text a set amount of space away from another shape or text by the bounding box. It only has to work in the X axis.
That way what ever i do with the previous shape (scale, Mask path, etc) the bounding box will automatically push the layers to the right without having to adjust.
Any help would be appreciated
If the Anchor point of the background (shape layer) or the text layer is in the center of the layer, and you have a Controls layer with a Slider Control added to it, all you have to do is add this expression to the position property of the layers below the first layer on the left.
// Set the layer with Controls
ctrl = thisComp.layer("Controls");
mrgn = ctrl.effect("H Margin")("Slider");
// Calculate half of the Width of the layer above this one
ref = thisComp.layer(index-1);
rPos = ref.positi
...
Copy link to clipboard
Copied
Sorry if i midunderstand, would it work just to parent the text/shape layer to the shape you're moving?
Copy link to clipboard
Copied
In normal situations that would work however im working on a job that has translation and so the width of words flucate and i might need to adjust the scale of shapes but i dont want to adjust everything else. only the position. Think of how websites are responive in design when shrinking the browser window down.
Copy link to clipboard
Copied
You need to combine sourceRectAtTime() with a scale multiplier and add that to the position property of the correct layers. Combine that with some simple addition, and multiple layers will line up and maintain position as the layers animate one of them or move the camera.
Show us your timeline and describe how the layers need to move, and I'll point you to an efficient workflow. I have about a dozen expression-based animation presets that do this kind of thing.
Copy link to clipboard
Copied
Heres an test example, basically i would want shape layer 1's bounding box to push shape layer 3 and 4 to only the right should i choose to scale "shape layer 1" up or down. On the project im working on having this be able to work with text would also be great. Let me know if this helps
Copy link to clipboard
Copied
If the Anchor point of the background (shape layer) or the text layer is in the center of the layer, and you have a Controls layer with a Slider Control added to it, all you have to do is add this expression to the position property of the layers below the first layer on the left.
// Set the layer with Controls
ctrl = thisComp.layer("Controls");
mrgn = ctrl.effect("H Margin")("Slider");
// Calculate half of the Width of the layer above this one
ref = thisComp.layer(index-1);
rPos = ref.position;
rSize = ref.sourceRectAtTime();
rScl = ref.scale[0]*.01;
rWidth = rSize.width/2 * rScl;
// Calculate half of the width of this layer
tLScale = scale[0] * .01;
tLWidth = sourceRectAtTime().width/2 * tLScale;
// Do the math
xPos = rPos[0] + rWidth + tLWidth + mrgn;
// Final Result
[xPos, rPos[1]]
There are workarounds if you use right- or left-justified text instead of center-justified text. You can also compensate for layers that don't have the anchor point in the center of the layer. If you use shape layers, you can also use this approach to offset multiple shapes in the same shape layer.
I have uploaded the project file for the sample I made. The expression will also work with text layers or even a mix of text and shape layers as long as the anchor points are at the layer's center.
Copy link to clipboard
Copied
Awesome, this is what i was looking for. You are the man!
One thing i didnt notice until i was applying the expression was that my anchor points were left aligned.
I tried adjusting the code but i couldnt figure it out. Where would i adjust things to account for a left middle aligned anchor point?
Copy link to clipboard
Copied
You can compensate for anchor point problems by using top and left values from sourceRectAtTime() and then throwing in a divide by 2.
I don't have time to modify the expression right now. I'll try later tomorrow.
Copy link to clipboard
Copied
great, thank you