Skip to content

Instantly share code, notes, and snippets.

@benwurth
Created September 21, 2013 00:58
Show Gist options
  • Save benwurth/6645905 to your computer and use it in GitHub Desktop.
Save benwurth/6645905 to your computer and use it in GitHub Desktop.
A simple script for After Effects that adds an expression for Inertial Bounce to the scale property of the selected layer (as opposed to another script I wrote that affects the position).
{
//Begins the undo group
app.beginUndoGroup("Add Inertial Bounce");
//Global Variables:
var bounceExp = "n = 0;if (numKeys > 0){n = nearestKey(time).index;if (key(n).time > time){n--;}}if (n == 0){t = 0;}else{t = time - key(n).time;}if (n > 0 && t < 1){v = velocityAtTime(key(n).time - thisComp.frameDuration/10);amp = .04;freq = 2.0;decay = 8.0;value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);}else{value;}";
var curItem = app.project.activeItem; //Creates variable that holds selected comp
//Functions:
function addBounce (currentLayer)
{
currentLayer.property("scale").expression = bounceExp;
}
//Main:
//Makes sure that there is an active comp
if (curItem === null || !(curItem instanceof CompItem))
{
alert ("Please establish a comp as the active item and run the script again.");
}
else
{
//Loop through layers
for (var i = 0; i <=(curItem.selectedLayers.length-1); i++)
{
//Define the layer in the loop we're currently looking at
var curLayer = curItem.selectedLayers[i];
//Check to see if curLayer is a footage layer
if (curLayer.matchName == "ADBE AV Layer")
{
//Add the bounce expression
addBounce(curLayer);
}
}
}
//Ends the undo group
app.endUndoGroup();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment