Let’s say you want to have the position of one element depend on the position of another - for example, having an element that underlines the last line of a multi-line text.
The problem is that if the number of lines of text changes, the underline element will be out of position.
To solve this, you can use an expression to tie the position of the underline element to the position of the last line of text.
Assume you have the following structure where there is a multi-line text field and a shape layer element that you want to position relative to the last line of text.
Layer 1 - Multi-line text layer
Shape 1 - Shape layer you want always positioned relative to Layer 1
The expression is applied to the position transform attribute on the Shape 1 layer.
The pattern here is to get the position of the independent element, adjusted for scale, and then set the position of the current element relative to that with some sort of buffer. This example above does it for y-position and it can similarly be done for x-position.
textLayer = thisComp.layer("Layer_1");
r = textLayer.sourceRectAtTime();
s = (textLayer.scale - 100) / 100;
textScaledHeight = r.height*(1+s);
buffer = 30;
textY = textLayer.position + textScaledHeight + buffer;
To change the position of design elements dynamically:
- Customize the highlighted portions of the expression above to use the layer names from your design
- Open up the position transform attribute for the Shape 1 composition and copy paste the updated expression