ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Auto Scaling expression

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Nathan Watson
Auto Scaling expression
on Aug 13, 2019 at 10:56:36 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.


Return to posts index

Dan Ebberts
Re: Auto Scaling expression
on Aug 13, 2019 at 3:42:03 pm

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

Dan



Return to posts index

Nathan Watson
Re: Auto Scaling expression
on Aug 13, 2019 at 7:04:59 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


Return to posts index


Dan Ebberts
Re: Auto Scaling expression
on Aug 13, 2019 at 7:12:54 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



Return to posts index

Dan Ebberts
Re: Auto Scaling expression
on Aug 13, 2019 at 7:18:47 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



Return to posts index

Nathan Watson
Re: Auto Scaling expression
on Aug 14, 2019 at 10:58:08 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


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]