Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Math.Max instead of if else

  • Math.Max instead of if else

  • Adam Greenberg

    November 11, 2022 at 1:57 am

    Hi, I have an expression I use often to scale down text once it reaches a certain length.

    I have applied it a null and parented 2 text layers to it, and used an if else statement to resize according to which text reaches that length first. The 2 layers need to stay the same relative size to each other, but their animations are different, so they need to stay as seperate text layers.

    Is it possible to rewrite this expression with a math.max instead of an if else. I am asking in case I have too many layers one day, here is my code as is, I have tried over and over to apply the math.max but it doesn’t work as expected;

    x= thisComp.layer(“TEXT1”).sourceRectAtTime(3).width;

    y= thisComp.layer(“TEXT2”).sourceRectAtTime(3).width;



    xclamp= clamp(a,1,100);

    yclamp= clamp(b,1,100);

    if(x>y) [xclamp,xclamp]; else [yclamp,yclamp]]


  • Dan Ebberts

    November 11, 2022 at 5:21 am

    I think you’d replace the last line with this:

    s = Math.max(xclamp,yclamp);
  • Adam Greenberg

    November 11, 2022 at 2:05 pm

    ya I thought so too, but it doesnt work. for some reason, it only work when both lines get to that maximum length, and even then it stops working at some point.

  • Adam Greenberg

    November 11, 2022 at 2:40 pm

    ok i think i fixed it, the 1920 divided by needs to be after the math.max.

    thanks so much, I wouldnt have been able to fix it without seeing yours first

    x= thisComp.layer(“TEXT1”).sourceRectAtTime(3).width;

    y= thisComp.layer(“TEXT2”).sourceRectAtTime(3).width;

    s = Math.max(x,y);


    xclamp= clamp(a,1,100);


Viewing 1 - 4 of 4 posts

Log in to reply.

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