Extending After Effects with Expressions
Expressions really open up After Effects to another level, and there’s just some things that you couldn’t do otherwise without a little bit of code to help out.
Below are some of our favourite expressions, picked up online over the years.
Number Counter with Prefix and Suffix Support
The Slider Control only goes up to 1,000,000, so for big numbers the Angle Control saves the day. Need decimals? Use the Slider Control.
Add the matching control to your text layer. With the Angle Control, you’ll be keyframing the full rotation number.
Automatic Anchor Positioning
Perfect for shape layers, text and anything else that changes size, making templating a little less tedious.
Maintain Scale when Parented
Thanks to Ben Marriott for this one, this expression when applied to the Scale property, maintains the layer’s original scale even while its parent’s scale changes. Check out Ben’s video here for a great example on how to use it.
s = [];
ps = parent.transform.scale.value;
for (i = 0; i < ps.length; i++) {
s[i] = value[i] * 100 / ps[i];
}
sMaintain Stroke Width
Putting this on your stroke width property means that regardless of the layer’s scale, the stroke will maintain the same thickness. Thanks to Ben Marriott and Adam Plouff for this code!
value / length(toComp([0,0]), toComp([0.7071,0.7071])) || 0.001;Looping Wiggle Expression
If you want your wiggle to be a touch more predictable and loop after a set amount of seconds, then below is for you!
Wiggle on One Axis
Dan Ebbert has a sweet little write up regarding this, and it essentially boils down that when you use the wiggle expression, it returns an array of values dependent on the property. For rotation, it’ll return one value, but when it comes to scale or position, it’ll return two, affecting both axes.
To affect just one axis, we split the wiggle open and only apply it where we want it.
Animating Frequency in a Wiggle
Oh boy, this one is a life saver. If you’ve tried to animate the frequency of a wiggle before, you’ll find out that After Effects likes to flip the table. MotionScript has an amazing writeup that I found when I was hunting a solution that really breaks down everything there is to the Wiggle function.
To use this, you’ll need a Slider Control (which represents your frequency amount) and apply this expression below to the property you wish to wiggle. Keyframe the slider to your heart’s desire and everything will function as expected.
Loop In and Out Continuously
Thanks to QuickLoop for this expression, it allows your property to loop both before and after your keyframes.
loopIn("Cycle") + loopOut("Cycle") - value;Looping a Path Property
The classic loopOut expressions sadly don’t work on Path properties, thankfully we have the expression below to help us out.
try {
timeStart = thisProperty.key(1).time;
duration = thisProperty.key(thisProperty.numKeys).time - timeStart;
pingPong = false; // change to true if you want to loop the animation back & forth
quant = Math.floor((time - timeStart) / duration);
if (quant < 0) quant = 0;
if (quant % 2 == 1 && pingPong == true) {
t = 2 * timeStart + (quant + 1) * duration - time;
} else {
t = time - quant * duration;
}
} catch (err) {
t = time;
}
thisProperty.valueAtTime(t)Overshoot
A classic expression. Apply this to a property for automatic, math driven overshoot.
Let's make gorgeous together
Got a brief, a half-formed idea or a deadline that's looking tight? Tell us what you're working on and we'll tell you honestly how we can help.
BasedMelbourne (Naarm), working Australia-wide
OpenMonday – Friday: 9:00am – 5:00pm
Happy hourMonday – Friday: 4:00pm – 5:00pm
