-
Expression to link other layers, when auto-scaling text.
Hi cows! I am trying out some expressions and I get stuck.
Let’s say I have three text layers that I want to put on top of each other like this:
TEXT1
TEXT2
TEXT3Where the bottom of text layer one is parented to the top of text layer 2, and the top of text later 3 is parents to the bottom of text layer 2.
I have an expression on these text layers to have the width not exceed the canvas size, for templating purposes, as for the text of all three needs to be changed dynamically. This means if the text on layer 2 has more characters, or gets longer, it will auto scale to fit the width.
(Using an expression on the scale property of these text layers, I will show the expression below…)The problem arises when I am trying to parent the position of the top and bottom text to the TEXT2 layer, as it seems to not respect the actual position with the sourceRectAtTime expression. -Oddly enough I did manage to get a null position linked to the exact position I want, but as I had to parent that whole null layer to the TEXT2 layer, it is effectively also scaling down the null.. (because of the expression on the scale value of the text layers…)
The current expression I have on the SCALE property of the TEXT layers is by using a shape layer that I am using as a guide for the text size :
var xWidth = thisComp.layer(“Text Sizer”).content(“Rectangle Path 1”).size[0];
var yHeight = thisComp.layer(“Text Sizer”).content(“Rectangle Path 1”).size[1];
var maxHeight = 100;
var heightMath = Math.min(maxHeight,yHeight);
var x = xWidth / sourceRectAtTime().width * 100;
var y = heightMath;
var minValue = Math.min(x,y);
[minValue,minValue]
The expression I got to work to parent a null layer to the top position of the TEXT 2 layer : <div>
textLayer = thisComp.layer(“Text2”);
rect = textLayer.sourceRectAtTime();
nullObjectPosition = [value[0], rect.top];
nullObjectPosition
(This works whilst also parenting the null layer to the TEXT layer…) Although that way the scale gets affected because of the expression on the text layers scale property…)</div><div>
Does anyone have any idea how to go about this? Any help would be greatly appreciated!
</div>