Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression to link other layers, when auto-scaling text.

  • Expression to link other layers, when auto-scaling text.

    Posted by Wick Van den belt on October 27, 2023 at 10:20 am

    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:


    Where 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);


    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],];


    (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!


    Adam Greenberg replied 8 months, 2 weeks ago 2 Members · 4 Replies
  • 4 Replies
  • Adam Greenberg

    October 30, 2023 at 5:55 pm

    Im trying to understand your issue. Are you trying to have the distance between the text layers stay fixed regardless of whether the text layer has scaled up or not ? so like example 10 pixels from text 1 to text 2 and text 3 but if text 1 scaled down because its really long you want the text 2 and text 3 to move up a little to maintain the relative distance ? or perhaps you want text 1 to move down and text 3 to move up ? where is your fixed point if this is the case. is it the bottom of layer 3 ? or is it text layer 2, and is it the bottom of text layer 2 or top of text layer 2 ?

  • Wick Van den belt

    October 31, 2023 at 8:38 pm

    Hi Adam, yes that is pretty much correct. So for just two text layers this is easy, as the anchor point for text 1 is on the bottom and for text2 the anchor point is on the top of that text layer. (So for big or small text size, they both scale of and the gap between them stays the same…)

    The issue is with the third text layer; I am trying to have that move along with the text layer 2 bottom position, which varies depending on the length of the text. -So the third text should ideally react to the bottom of text two, but I have tried endlessly to create expressions but I can’t get it to work.

    Most likely because the scale on the text layers makes the sourceRectAtTime expression fails to get the exact position? Which is weird, as I do manage to get a null linked to the exact position of the bottom of text two, but it just won’t work for text layer three.

  • Adam Greenberg

    November 1, 2023 at 5:26 pm

    ok i need to find my project that has this built in, I have done it before, Ill post back again soon with the solution if someone else doesnt beat me to it

  • Adam Greenberg

    November 1, 2023 at 5:45 pm

    you may have to copy paste what you need, but this is a reduced project of a project i have that uses it. you could redo the nulls and expressions for the anchor point of all of it to be on text 1 or 3 instead of text 2 ( which it is in this project ). also you could change the math on the maximum horizontal size of the text. and i just realized mine is left justified and yours is center. hopefully it helps you out.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy