Copy link to clipboard
Copied
Hello. Despite trying with ChatGPT's assistance, I couldn't get the correct answer, so I'm posting my question here.
I have two text layers named "Ch_Name" and "C&C" in After Effects.
The text layer "C&C" is positioned next to the text in the "Ch_Name" layer.
I want the position of the "C&C" text layer to automatically adjust and maintain the same spacing relative to the "Ch_Name" text layer when the content of "Ch_Name" text layer changes in length.
Could you please advise how to write an expression to achieve this?
Copy link to clipboard
Copied
The magic word to look for is sourceRectAtTime() and when you type that in I'm sure even dumb ChatGPT will offer something as will a broader Google search.
Mylenium
Copy link to clipboard
Copied
I should take this opportunity to study how to use the sourceRectAtTime() expression!
Copy link to clipboard
Copied
If you add this expression to the position property of the second layer and it is below the first layer, the text will always be 20 pixels right of the second layer as long as the baseline shift is set to zero and the paragraph justification is set to Left.
ref = thisComp.layer(index-1);
p = ref.position;
L1 = ref.sourceRectAtTime();
L2 = sourceRectAtTime();
pad = 20; // 20 pixel pad
rtEdge = L1.left + L1.width;
x = L2.left;
p + [rtEdge + pad + x, 0]
You can get a lot fancier, but this will do for a basic setup. It should give you a starting point.
Copy link to clipboard
Copied
Thank you so much for your incredible work!