Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Auto Scaling expression

  • Auto Scaling expression

    Posted by Nathan Watson on August 13, 2019 at 10:56 am

    Hey guys, currently have this expression:

    margin = 0
    text_width = thisLayer.sourceRectAtTime(time).width;
    text_height = thisLayer.sourceRectAtTime(time).height;
    rect_height = thisComp.layer("S").height*thisComp.layer("S").scale[1]/100-2*margin;
    rect_width = thisComp.layer("S").width*thisComp.layer("S").scale[0]/100-2*margin;
    s = Math.min(rect_width/text_width*100, rect_height/text_height*100);
    [s,s]

    But need some help in changing it so it also takes into account the keyframes I have set on a layer.
    This code currently automatically scales a piece of text, well, anything I suppose, to the size of a box I have in the composition, but I have other keyframes on the text that change the scale for effect and currently this completely overwrites them.

    Any help is greatly appreciated!
    Cheers,
    Nathan.

    Nathan Watson replied 7 years ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    August 13, 2019 at 3:42 pm

    What do you mean by “takes into account the keyframes”? In what way?

    Dan

  • Nathan Watson

    August 13, 2019 at 7:04 pm

    So if I were to have a keyframe in there that changes the value from 100% to 50% it’d actually do that rather than be a static value that the expression makes it

  • Dan Ebberts

    August 13, 2019 at 7:12 pm

    So something like this?


    if (numKeys > 0){
    margin = 0;
    text_width = thisLayer.sourceRectAtTime(time).width;
    text_height = thisLayer.sourceRectAtTime(time).height;
    rect_height = thisComp.layer("S").height*thisComp.layer("S").scale[1]/100-2*margin;
    rect_width = thisComp.layer("S").width*thisComp.layer("S").scale[0]/100-2*margin;
    s = Math.min(rect_width/text_width*100, rect_height/text_height*100);
    [s,s]
    }else
    value

    Dan

  • Dan Ebberts

    August 13, 2019 at 7:18 pm

    Sorry, that was backwards:


    if (numKeys == 0){
    margin = 0;
    text_width = thisLayer.sourceRectAtTime(time).width;
    text_height = thisLayer.sourceRectAtTime(time).height;
    rect_height = thisComp.layer("S").height*thisComp.layer("S").scale[1]/100-2*margin;
    rect_width = thisComp.layer("S").width*thisComp.layer("S").scale[0]/100-2*margin;
    s = Math.min(rect_width/text_width*100, rect_height/text_height*100);
    [s,s]
    }else
    value

    Dan

  • Nathan Watson

    August 14, 2019 at 10:58 am

    Sort of, I still want it to actually change the scale no matter what to fit the box that I have it scaling to, but just include the keyframes I have as an additional factor into the value to scale it to

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