Your screen is too tiny!

The expressions page is currently only formatted for desktop browsers.

Try making your screen size bigger.

Plus, why are you looking at AE Expressions on a phone? That's kinda dorky.
Expression Copied to Clipboard! 🗂
Delay Keyframes With Slider
Use a slider control to delay keyframe animation by a defined amount of seconds. Works like a marker trigger, but simpler. Useful for MOGRTs
delay = thisComp.layer("Controls").effect("Delay")("Slider"); // pickwhip to your Delay Slider (in seconds) valueAtTime(time-delay)
Wiggle on One Dimension
Constrain wiggle to One Dimension (X or Y). NOTE: Wiggles X dimension. For Y dimension only, change last line to [value[0],w[1]]
frequency = 2; amplitude = 10; w = wiggle(frequency, amplitude); // wiggles on X dimension. To wiggle on Y, change the last line to // [value[0],w[1]] [w[0],value[1]]
Wiggle between two value
Wiggle randomly between two values.
min = -10; // minimum value max = 50; // maximum value freq = 5; // wiggles per second amp = Math.abs(max-min)/2; // amount to wiggle offset = (max+min)/2; wiggle(f, a) + offset;
Trigger Expression on Marker
Boilerplate expression to trigger actions with markers
n=0; if(marker.numKeys>0) { n=marker.nearestKey(time).index; if(marker.key(n).time>time) { n--; } if(n==0) { value; } else { t=time-marker.key(n).time; //time since marker //Do Stuff } } else { value; }
Show/Hide Layer With Dropdown
Apply to opacity property of a layer. Change name of layer to start with [1,2,3] to match the Dropdown control.
select = thisComp.layer("CONTROLS").effect("Background Version")("Menu").value; if (select === parseInt(thisLayer.name.charAt(0))){ 100 } else { 0 }
Scale Layer to a Certain Width
Scale a layer to fit a pixel width. Apply to scale property
s = 100*{{WIDTH}}/thisLayer.width; [s,s]
Posterize Time + Wiggle
Add a posterize time stop motion effect with the wiggle expression.
f = 2; a = 10; posterizeTime(f); wiggle(f, a);
Max Width Scale of Text Layer
Constrain the max width of a text layer using the scale property
maxW = effect("max-width")("Slider"); sourceW = sourceRectAtTime(time,true).width; if(sourceW >= maxW ){ s = value[0]*maxW/sourceW; [s,s] } else { value }
Maintain Stroke Width
Maintain stroke width while scaling layers. Apply to stroke width property
value / length(toComp([0,0]), toComp([0.7071,0.7071])) || 0.001; // apply to "Stroke Width" property to maintain size of stroke
Loop Path Keyframes
Seamlessly loop keyframes on a Path Property for shape layers or masks.
// loop path keyframes. Behaves like loopOut('cycle') if (numKeys >1 && time > key(numKeys).time) { t1 = key(1).time; t2 = key(numKeys).time; span = t2 - t1; delta = time - t2; t = delta%span; valueAtTime(t1 + t) } else { value } // more expressions at aereference.com
Loop In and Out
Loop an animation both forward and backwards in time
loopIn() + loopOut() - value;
Loop a Wiggle
Seamlessly loop a wiggle expression (in seconds)
frequency = 2; // wiggles per second amplitude = 40; // amount of pixels to wiggle secondsToLoop = 3; // time to loop in seconds // -------- t = time % secondsToLoop; wiggle1 = wiggle(frequency, amplitude, 1, 0.5, t); wiggle2 = wiggle(frequency, amplitude, 1, 0.5, t - secondsToLoop); linear(t, 0, secondsToLoop, wiggle1, wiggle2)
Invert Opacity
Alternate opacity with the opacity of another layer.
t = thisComp.layer("Back").transform.opacity // Pickwhip the layer you want to invert linear(t,0,value,100,0)
Inherit Parent Opacity (editable)
Inherits opacity from parent but retains the child's editabilty
(hasParent) ? (parent.opacity/100) * value : value;
Inherit Parent Opacity
Inherit Opacity from parent layer
(hasParent) ? parent.opacity : value;
Ignore Parent Scale (if parent has parent)
Maintain scale of a layer when parented to another layer - even if that layer has a parent. Apply to scale property of child layer.
L = thisLayer; s = transform.scale.value; while (L.hasParent){ L = L.parent; for (i = 0; i < s.length; i++) s[i] *= 100/L.transform.scale.value[i] } s
Ignore Parent Scale
Maintain scale of a layer when parented to another layer. Apply to scale property of child layer.
s = []; parentScale = parent.transform.scale.value; for (i = 0; i < parentScale.length; i++){ s[i] = (parentScale[i]== 0) ? 0 : value[i]*100/parentScale[i]; } s
Ignore Parent Rotation
Keep the current rotation of child, even when parent rotates.
value - parent.transform.rotation
Get Current Date and Format
Useful snippet for getting current date
d = new Date(Date(0)); // Format Settings divider = "/" yearLength = 2; // use 2 for YY, 4 for YYYY function padZeros(n){ if(n <= 9){ return "0" + n; } return n } yearTrim = (yearLength===2) ? 2 : 0; "" + padZeros(d.getMonth()+1) + divider + padZeros(d.getDate()) + divider + d.getFullYear().toString().substring(yearTrim,4);
Frozen Random Number
Generate a random number
seedRandom(index,true); myValue = random(50) ;
Dropdown Menu Select
Control the opacity of a layer by the dropdown menu selection. Add a Number [1,2,3,etc] to the beginning of layer to make it work
select = thisComp.layer("CONTROLS").effect("Face Select")("Menu"); (select == parseInt(thisLayer.name[0])) ? value : 0;
Delay
Delay property by certain number of frames
delay = 5; //number of frames to delay d = delay*thisComp.frameDuration*(index - 1); thisComp.layer(1).rotation.valueAtTime(time - d)
Control Shape Layer Position with Null
Control shape layer position with a Null - works like parenting, but keeps the relative position of your shape layer.
control=thisComp.layer("Control NULL"); // your controller null controlPos = control.toComp(control.transform.anchorPoint); fromComp(controlPos) // apply to position property
Control Property with Checkbox
Apply this expression to the property you want to control (like opacity) and make sure it is referencing the correct control layer.
thisComp.layer("Controls").effect("Control Name")("Checkbox") * value;
Center Anchor Point Vertically on Text
Make the anchor point always vertically centered on a text layer
y=value[1]-sourceRectAtTime(time).height/2; [0,y]
Auto Fade In & Out by Marker Duration
Fade a layer in and out using markers to set the duration
fadeFrames = 6; m = 0; t=time; if(marker.numKeys > 0) { m = marker.nearestKey(time).index; tag = marker.key(m).comment; if(tag == 'Highlight'){ tMin = marker.key(m).time; tMax = tMin + marker.key(m).duration; if(t < tMin){ linear(time, tMin - framesToTime(fadeFrames), tMin, 0, value); } else { linear(time, tMax - framesToTime(fadeFrames), tMax, value, 0); } } else { value; } } else {value}
2D to 3D Null
Attach a 2D position a 3D Null
thisComp.layer("3D Layer Name").toComp([0,0,0]);

Delay Keyframes With Slider

Use a slider control to delay keyframe animation by a defined amount of seconds. Works like a marker trigger, but simpler. Useful for MOGRTs

Copied to Clipboard!
delay = thisComp.layer("Controls").effect("Delay")("Slider"); // pickwhip to your Delay Slider (in seconds) valueAtTime(time-delay)

Wiggle on One Dimension

Constrain wiggle to One Dimension (X or Y). NOTE: Wiggles X dimension. For Y dimension only, change last line to [value[0],w[1]]

Copied to Clipboard!
frequency = 2;
amplitude = 10;
w = wiggle(frequency, amplitude);
// wiggles on X dimension. To wiggle on Y, change the last line to
// [value[0],w[1]]
[w[0],value[1]]

Wiggle between two value

Wiggle randomly between two values.

Copied to Clipboard!
min = -10; // minimum value
max = 50; // maximum value
freq = 5; // wiggles per second
amp = Math.abs(max-min)/2; // amount to wiggle
offset = (max+min)/2;
wiggle(f, a) + offset;

Trigger Expression on Marker

Boilerplate expression to trigger actions with markers

Copied to Clipboard!
n=0;
if(marker.numKeys>0) { n=marker.nearestKey(time).index; if(marker.key(n).time>time) { n--; } if(n==0) { value; } else { t=time-marker.key(n).time; //time since marker //Do Stuff }
} else { value;
}

Replace ‘//Do Stuff’ with code to be triggered at a maker.

One use is to trigger keyframed animation from the begining of the layer (eg. valueAtTime(inPoint+t))


‍

Show/Hide Layer With Dropdown

Apply to opacity property of a layer. Change name of layer to start with [1,2,3] to match the Dropdown control.

Copied to Clipboard!
select = thisComp.layer("CONTROLS").effect("Background Version")("Menu").value;

if (select === parseInt(thisLayer.name.charAt(0))){ 100 } else { 0 }

Link select variable to your Dropdown menu.

IMPORTANT: be sure to rename your layer to start with the number that corresponds to the dropdown menu.


Example:

1_Background Design A  ----> linked to dropdown menu selection 1

2_Background Design B ----> linked to dropdown menu selection 1

‍

Scale Layer to a Certain Width

Scale a layer to fit a pixel width. Apply to scale property

Copied to Clipboard!
s = 100*/thisLayer.width;
[s,s]

Posterize Time + Wiggle

Add a posterize time stop motion effect with the wiggle expression.

Copied to Clipboard!
f = 2;
a = 10;
posterizeTime(f);
wiggle(f, a);

Max Width Scale of Text Layer

Constrain the max width of a text layer using the scale property

Copied to Clipboard!
maxW = effect("max-width")("Slider");
sourceW = sourceRectAtTime(time,true).width;

if(sourceW >= maxW ){
	s = value[0]*maxW/sourceW;
[s,s]
} else {
	value
}

Maintain Stroke Width

Maintain stroke width while scaling layers. Apply to stroke width property

Copied to Clipboard!
value / length(toComp([0,0]), toComp([0.7071,0.7071])) || 0.001;
// apply to "Stroke Width" property to maintain size of stroke

How to Use

Apply this expression to the Stroke Width property of any shape layer to maintain the visual thickness of the stroke, no matter what scaling is applied to the layer.

Loop Path Keyframes

Seamlessly loop keyframes on a Path Property for shape layers or masks.

Copied to Clipboard!
// loop path keyframes. Behaves like loopOut('cycle')
if (numKeys >1 && time > key(numKeys).time) {
	t1 = key(1).time;
	t2 = key(numKeys).time;
	span = t2 - t1;
	delta = time - t2;
	t = delta%span;
	valueAtTime(t1 + t)
} else {
	value
}
// more expressions at aereference.com

How to Use

Apply the above expression to the path property on a shape layer or mask to loop your keyframes like a normal loopOut("cycle")


About

Many tasks in animation can benefit from looping (repeating the same thing over and over). In many cases, you can apply one of After Effect's default looping expressions loopOut("cycle") expression. (Or the improved loop in and out expression)


Unfortunately, those don't work on animated Paths.


This expression allows you to loop keyframes on an animated path - handy for creating custom animations on shape layers or masks without having to copy/paste a lot.

‍

Loop In and Out

Loop an animation both forward and backwards in time

Copied to Clipboard!
loopIn() + loopOut() - value;

Loop a Wiggle

Seamlessly loop a wiggle expression (in seconds)

Copied to Clipboard!
frequency = 2; // wiggles per second
amplitude = 40; // amount of pixels to wiggle
secondsToLoop = 3; // time to loop in seconds
// --------
t = time % secondsToLoop;
wiggle1 = wiggle(frequency, amplitude, 1, 0.5, t);
wiggle2 = wiggle(frequency, amplitude, 1, 0.5, t - secondsToLoop);
linear(t, 0,  secondsToLoop, wiggle1, wiggle2)

How to Use

Apply this expression to any property to get a random wiggle value that loops every n seconds.


frequency = the amount of wiggles per second


amplitude = the amount (pixels, percent) you want the wiggle to vary


secondsToLoop = how many seconds you want the loop to last


About

wiggle(f,a) is one of the most common and useful expressions for adding randomness and variation to properties in After Effects. However, it doesn't loop easily by default.

This expression allows you to create a looping wiggle by cleverly animating between 2 different wiggle expressions.


‍

Invert Opacity

Alternate opacity with the opacity of another layer.

Copied to Clipboard!
t = thisComp.layer("Back").transform.opacity // Pickwhip the layer you want to invert

linear(t,0,value,100,0)

Inherit Parent Opacity (editable)

Inherits opacity from parent but retains the child's editabilty

Copied to Clipboard!
(hasParent) ? (parent.opacity/100) * value : value;

The parent's opacity value acts as a mulitplier for the child's

Inherit Parent Opacity

Inherit Opacity from parent layer

Copied to Clipboard!
(hasParent) ? parent.opacity : value;

The parent's opacity value acts as a multiplier for the child's

Ignore Parent Scale (if parent has parent)

Maintain scale of a layer when parented to another layer - even if that layer has a parent. Apply to scale property of child layer.

Copied to Clipboard!
L = thisLayer;
s = transform.scale.value;
while (L.hasParent){
L = L.parent;
for (i = 0; i < s.length; i++) s[i] *= 100/L.transform.scale.value[i]
}
s

Ignore Parent Scale

Maintain scale of a layer when parented to another layer. Apply to scale property of child layer.

Copied to Clipboard!
s = [];
parentScale = parent.transform.scale.value;
for (i = 0; i < parentScale.length; i++){
s[i] = (parentScale[i]== 0) ? 0 : value[i]*100/parentScale[i];
}
s

Ignore Parent Rotation

Keep the current rotation of child, even when parent rotates.

Copied to Clipboard!
value - parent.transform.rotation

Get Current Date and Format

Useful snippet for getting current date

Copied to Clipboard!
d = new Date(Date(0));
// Format Settings
divider = "/"
yearLength = 2; // use 2 for YY, 4 for YYYY

function padZeros(n){
  if(n <= 9){
    return "0" + n;
  }
  return n
}
yearTrim = (yearLength===2) ? 2 : 0;
"" + padZeros(d.getMonth()+1) + divider + padZeros(d.getDate()) + divider + d.getFullYear().toString().substring(yearTrim,4);

Frozen Random Number

Generate a random number

Copied to Clipboard!
seedRandom(index,true);
myValue = random(50) ;

Dropdown Menu Select

Control the opacity of a layer by the dropdown menu selection. Add a Number [1,2,3,etc] to the beginning of layer to make it work

Copied to Clipboard!
select = thisComp.layer("CONTROLS").effect("Face Select")("Menu");
(select == parseInt(thisLayer.name[0])) ? value : 0;

Delay

Delay property by certain number of frames

Copied to Clipboard!
delay = 5; //number of frames to delay
d = delay*thisComp.frameDuration*(index - 1);
thisComp.layer(1).rotation.valueAtTime(time - d)

DELAY FOR SPECIFIC LAYER

lay = thisComp.layer("SquareMoves")
delay = 1; //number of frames to delay
d = delay*thisComp.frameDuration;
lay.rotation.valueAtTime(time - d)

Better documentation coming soon!

(this one is a little messy plz forgive me I'm a busy boy)

‍

Control Shape Layer Position with Null

Control shape layer position with a Null - works like parenting, but keeps the relative position of your shape layer.

Copied to Clipboard!
control=thisComp.layer("Control NULL"); // your controller null
controlPos = control.toComp(control.transform.anchorPoint);
fromComp(controlPos)
// apply to position property

Control Property with Checkbox

Apply this expression to the property you want to control (like opacity) and make sure it is referencing the correct control layer.

Copied to Clipboard!
thisComp.layer("Controls").effect("Control Name")("Checkbox") * value;

Center Anchor Point Vertically on Text

Make the anchor point always vertically centered on a text layer

Copied to Clipboard!
y=value[1]-sourceRectAtTime(time).height/2;
[0,y]

Auto Fade In & Out by Marker Duration

Fade a layer in and out using markers to set the duration

Copied to Clipboard!
fadeFrames = 6; m = 0; t=time;
if(marker.numKeys > 0) {
	m = marker.nearestKey(time).index;
	tag = marker.key(m).comment;
	if(tag == 'Highlight'){
		tMin = marker.key(m).time;
		tMax = tMin + marker.key(m).duration;
		
		if(t < tMin){
			linear(time, tMin - framesToTime(fadeFrames), tMin, 0, value);
		} else {
			linear(time, tMax - framesToTime(fadeFrames), tMax, value, 0);
		}
	} else {
		value;
	}
} else {value}

Better documentation coming soon!

(this one is a little messy plz forgive me I'm a busy boy)

‍

2D to 3D Null

Attach a 2D position a 3D Null

Copied to Clipboard!
thisComp.layer("3D Layer Name").toComp([0,0,0]);