Skip to main content
Inspiring
April 17, 2024
Question

I want to maintain the spacing between two text layers.

  • April 17, 2024
  • 2 replies
  • 585 views

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?

This topic has been closed for replies.

2 replies

Community Expert
April 17, 2024

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. 

Bunny.cAuthor
Inspiring
April 18, 2024

Thank you so much for your incredible work!

Mylenium
Legend
April 17, 2024

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

Bunny.cAuthor
Inspiring
April 18, 2024

I should take this opportunity to study how to use the sourceRectAtTime() expression!