Skip to main content
Inspiring
Apr 17, 2024 4:17 AM UTC
Question

I want to maintain the spacing between two text layers.

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 is closed to new replies. Start a new post to keep the conversation going.

4 replies

Community Expert
Apr 17, 2024 9:11 PM UTC

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. 

Translate
Bunny.cAuthor
Inspiring
Apr 18, 2024 4:08 AM UTC

Thank you so much for your incredible work!

Translate
Mylenium
Legend
Apr 17, 2024 7:41 AM UTC

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

Translate
Bunny.cAuthor
Inspiring
Apr 18, 2024 4:09 AM UTC

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

Translate