Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions How to change textsize through sourceRectAtTime with if/else based on textwidth?

  • How to change textsize through sourceRectAtTime with if/else based on textwidth?

  • Las Wen

    January 24, 2022 at 11:16 am

    Hi there…

    i was trying to change the textsize by reading the sourceRectatTime width with an if/else condition. It seems like jumping forward backward then (it doesnt work). Do i need to use the loop function? I am very beginner with all this, but try to understand more 🙂 i was trying to make a kind of responsive text or like having breakpoints.

    this was my tryout:
    var a = thisLayer.sourceRectAtTime();
    if(a.width > 600) {
    thisLayer.text.sourceText.style.setFontSize(200)
    }
    else {
    thisLayer.text.sourceText.style.setFontSize(100)
    };
  • Andrei Popa

    January 24, 2022 at 5:05 pm

    I do not think you can do it this way. Modifying the font size modifies the sourceRectAtTime, then the expression runs again and so on.

    What you could do is duplicate the text layer and get the sourceRectAtTime from that one (you can make it invisible). Then, based on the value, modify the font size on the current layer.

  • Las Wen

    January 24, 2022 at 6:17 pm

    I did not get it to work. Is there a way to purge the cache before or after the expression is operated by an other expression?

  • Adam Greenberg

    January 25, 2022 at 7:05 pm

    you can also apply this expression to the scale of the text layer itself, but you would need to do a little math; try something like this but you will have to modify it, likely 59 is not your magic number. also pay attention to your anchor point.

    x= 1920/thisLayer.sourceRectAtTime(time).width*59;

    [x,x]

    and I assume you dont want the text to get bigger so better to clamp it at 100%

    so this instead

    x= 1920/thisLayer.sourceRectAtTime(time).width*59;

    yclamp= clamp(x,1,100);

    [yclamp,yclamp]

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