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

Expression to set position of text layer base on a different text layer

New Here ,
Feb 22, 2023 Feb 22, 2023

I'm quite sure this question has been asked and answered -- happy to look at any existing threads I've missed or expressions I may not have tried.

 

Obviously, new to expressions here.  I'm working on a lower third that's made up of two text layers:

 

Layer 1| Layer 2

 

Layer 1 has a different line weight and size than Layer 2.  I want to export a .mogrt where Layer 2's position will change, relative to the ending position of Layer 1.  in the .mogrt, source text will be editable in both layers.

 

Thanks for any advice and patience with a simple question.

TOPICS
Expressions , FAQ , How to
1.9K
Translate
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 ,
Feb 22, 2023 Feb 22, 2023

The approach to this kind of problem is to tie the position of text layer 2 to text layer 1 with an expression that looks at the position of layer 1 and calculates the true position of the text block in layer 1 using sourceRectAtTime() and then uses the left, width, top, and height as well as the sourceRectAtTime() properties of the text layer 2 to adjust the position of layer 2 while compensating for baseline shift (top + height) and paragraph justification (left and width). You only need an expression for Laye2, and I would use thisComp.layer(index - 1) instead of the layer's name in the composition. You have to do the math so the second layer goes where you want it to go, plus a bit of padding. 

 

Try something like this to make layer 2's baseline line up with Layer 1's baseline and position Layer 2 to the right of layer 1.

 

L2 = sourceRectAtTime();
L1 = thisComp.layer(index -1);
pad = 30;
p = L1.position;
s = L1.sourceRectAtTime();
x = s.width + s.left;
y = s.height + s.top;
p + [x + L2.left + pad, 0];

 

As long as you have not fiddled with Baseline Shift and the second text layer, Paragraph justification is set to Left, that expression should keep things lined up and both layers at the same level. 

Translate
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
New Here ,
Feb 23, 2023 Feb 23, 2023
Thanks so much for your help, Rick. This worked – L2’s y value was a little off, but I added -8 after to the y value at the end of the expression and that put L2 in the right place.

Iain
Translate
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 ,
Feb 23, 2023 Feb 23, 2023

The expression assumes that there is no baseline shift and that you don't want to line up the defenders on the second layer. If I were building a MOGRT, I would add a slicer to fine-tune the offset and another one for the padding. 

Translate
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
Engaged ,
Dec 24, 2023 Dec 24, 2023
LATEST

Mmm this is great, but what if you want

 

Layer1

Layer2

 

And if layer1 gets 2 sublines of text. ; layer2 moves down automaticly?

 

Layer1 (line1)

Layer1 (line2)

Layer2

Translate
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