Copy link to clipboard
Copied
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):
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]
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:
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...
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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:
Copy link to clipboard
Copied
This is just perfect!
Thank you very very much.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more