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

Maintain vertical distance between text layers (each line with a bounding box)

New Here ,
Oct 31, 2023 Oct 31, 2023

I'm making a template for an adjustable lettering with a bounding box for each line. I'm almost done, but there's a final issue I just can't wrap my head around.

 

I'm trying to use sourceRectAtTime to autosize the boxes and automatically distribute the layers vertically. Here's my setup:

 

The box shape layers sizes are working fine (It's just like the Jake Barlett tutorial):

  • Size property:

var s = thisComp.layer("txt 1");

var w = s.sourceRectAtTime().width + effect("Ajuste W")("Slider");

var h = s.sourceRectAtTime(3).height + effect("Ajuste H")("Slider");

 

[w,h]

 

  • Position property:

var s = thisComp.layer("txt 1");

var w = s.sourceRectAtTime().width/2;

var h = s.sourceRectAtTime(3).height/2;

var l = s.sourceRectAtTime(3).left;

var t = s.sourceRectAtTime(3).top;

 

[w+l,h+t]



This works fine most of the time, but in Brazil we speak portuguese and there's a lot of accents: ´`^~. If there's an accent on a capital letter (Á, Ô, etc), the distances just don't stay the same.

 

Here's what I tried to fix that:

I parented the boxes to each text layer, then I applied this expression to the position property of the text layers:

var src=thisComp.layer(index + 1);

var src2 = thisLayer;

var srcHeight = src.sourceRectAtTime(3).height;

var src2Top = src2.sourceRectAtTime(3).top;

var pad = thisComp.layer("ctrl").effect("entrelinhas")("Slider") // distance between layers

var newY = srcHeight - src2Top + pad;

var strtPos = src.position;

 

[strtPos[0], strtPos[1] + newY]

 

This last part is not working as I wanted. The distances between lines don’t stay constant. Only if there’d be an accented capital letter on each of the lines. Unfortunately that’s not what’d happen. Here are some screenshots of the problem:


print 1.pngprint 2.pngprint 3.pngprint 4.png

TOPICS
Expressions , How to
865
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

correct answers 1 Correct answer

Community Expert , Nov 01, 2023 Nov 01, 2023

To maintain even spacing between text layers, you need to get the height and top of the layer above and combine that with the top value of the text layer below. If you put a shape layer as a background below the text layers then you can use index-2 to look at the layers. Then you need to add in an offset.

 

Here's the expression for the position on the text layers that are below the first text layer:

srcLyr = thisComp.layer(index - 2);
srcScl = srcLyr.scale * .01;
srcPos = srcLyr.position;
srcRe
...
Translate
LEGEND ,
Nov 01, 2023 Nov 01, 2023

I think there's simply a bug  where the values are not sampled correctly with exteneded characters. Anway, why not simply dial in a fixed absolute value for the height and only use the width?

 

Mylenium

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 ,
Nov 01, 2023 Nov 01, 2023

To maintain even spacing between text layers, you need to get the height and top of the layer above and combine that with the top value of the text layer below. If you put a shape layer as a background below the text layers then you can use index-2 to look at the layers. Then you need to add in an offset.

 

Here's the expression for the position on the text layers that are below the first text layer:

srcLyr = thisComp.layer(index - 2);
srcScl = srcLyr.scale * .01;
srcPos = srcLyr.position;
srcRec = srcLyr.sourceRectAtTime();
srcH = srcRec.height;
srcT = srcRec.top;
lyrT = thisLayer.sourceRectAtTime().top;
srcOfst = (srcH + srcT) * srcScl[1];
vPad = 80;
[srcPos[0], srcPos[1] + srcOfst - lyrT + vPad]

You need to adjust the vPad value to adjust the spacing between layers. This expression compensates for any changes in Scale on the layers.

 

Here are the expressions for the shape layers that are in between the text layers:

//Rectangle Size
ref = thisComp.layer(index - 1);
hPad = 50;
vPad = 100;
box = ref.sourceRectAtTime();
h = box.height + hPad;
w = box.width + vPad;
[w, h]

// Shape layer Position
ref = thisComp.layer(index - 1);
p = ref.position;
box = ref.sourceRectAtTime();
h = box.top + box.height/2;
w = box. left + box.width/2;
[w, h] + p;

This is what it looks like with four text layers with backgrounds:

RickGerard_0-1698824596549.png

 

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 ,
Nov 06, 2023 Nov 06, 2023
LATEST

This is just perfect!

Thank you very very much. 

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