• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

I want to maintain the spacing between two text layers.

Community Beginner ,
Apr 16, 2024 Apr 16, 2024

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?

TOPICS
Expressions

Views

209

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 17, 2024 Apr 17, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 17, 2024 Apr 17, 2024

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2024 Apr 17, 2024

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 17, 2024 Apr 17, 2024

Copy link to clipboard

Copied

Thank you so much for your incredible work!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines