Motion Graphics
Blog Category

After Effects Expressions Library

Here's a collection of my most used After Effects expressions. I reference this list regularly, so I figured it could be useful for others so I've included it on my site.

Automatic Fade

transition = 20;
if (marker.numKeys<2){
tSecs = transition / ( 1 / thisComp.frameDuration);
linear(time, inPoint, inPoint + tSecs, 0, 100) linear(time, outPoint - tSecs, outPoint, 0, 100)}
else{linear(time, inPoint, marker.key(1).time, 0, 100) linear(time, marker.key(2).time, outPoint, 0, 100)}

Anchor Point

Top Left

a = thisComp.layer(index).sourceRectAtTime();
height = a.height; width = a.width; top = a.top; left = a.left;
x = left; y = top;
[x,y];

Top Right

a = thisComp.layer(index).sourceRectAtTime();
height = a.height; width = a.width; top =a.top; left = a.left;
x = left + width; y = top;
[x,y];

Bottom Left

a = thisComp.layer(index).sourceRectAtTime();
height = a.height; width = a.width; top =a.top; left = a.left;
x = left; y = top + height;
[x,y];

Bottom Right

a = thisComp.layer(index).sourceRectAtTime();
height = a.height; width = a.width; top = a.top; left = a.left;
x = left + width; y = top + height;
[x,y];

Centre

a = thisComp.layer(index).sourceRectAtTime();
height = a.height; width = a.width; top =a.top; left = a.left;
x = left + width/2; y = top + height/2;
[x,y];
‍

Clamp

clamp(transform.yPosition, min,max)

Loop Keyframes

Cycle

loopOut("cycle");

Pingpong

loopOut(“pingpong”)

Position Shape to Top Right Corner of layer below

l = thisComp.layer(index+1);
l.toComp([l.sourceRectAtTime(time).left + l.sourceRectAtTime(time).width,l.sourceRectAtTime(time).top]);

Responsive Shape Size

Width

x = thisComp.layer("name").sourceRectAtTime().width;
[x, value[1]]

Height

y = thisComp.layer("name").sourceRectAtTime().height;
[value[0],y]

Width & Height

x = thisComp.layer("name").sourceRectAtTime().width;
y = thisComp.layer("name").sourceRectAtTime().height;
[x,y]

Round Numbers

Timer

Math.round(time)

‍

‍