Skip to content

Instantly share code, notes, and snippets.

@justintaylor-dev
Created July 2, 2019 16:48
Show Gist options
  • Save justintaylor-dev/c712d1ae3257e2d4a14b063bb7dbefa2 to your computer and use it in GitHub Desktop.
Save justintaylor-dev/c712d1ae3257e2d4a14b063bb7dbefa2 to your computer and use it in GitHub Desktop.
ease-all-keyframes #code_aeft
// Gets all properties with keyframes in a layer
function getPropsWithKeys(layer) {
var numRootProps = layer.numProperties;
var propsWithKeys = [];
for (var i = 0; i < numRootProps; i++) {
var prop = layer(i + 1);
var isGroup = prop.numProperties && prop.numProperties > 0;
if (isGroup) {
for (var j = 0; j < prop.numProperties; j++) {
var subProp = prop.property(j + 1);
var isSubGroup =
subProp.numProperties && subProp.numProperties > 0;
if (isSubGroup) {
for (var k = 0; k < subProp.numProperties; k++) {
var subSubProp = subProp.property(k + 1);
if (subSubProp.numKeys > 0) {
propsWithKeys.push(subSubProp);
}
}
} else {
if (subProp.numKeys > 0) {
propsWithKeys.push(subProp);
}
}
}
} else {
if (prop.numKeys > 0) {
propsWithKeys.push(prop);
}
}
}
return propsWithKeys;
}
// Loop through and apply Custom Easing to all keyframes
var keyedProps = getPropsWithKeys(app.project.activeItem.layers[1]);
for (var i = 0; i < keyedProps.length; i++) {
var curProp = keyedProps[i];
var numKeys = curProp.numKeys;
for (var j = 0; j < numKeys; j++) {
var curKeyIndex = j + 1;
var easeIn = new KeyframeEase(0.5, 50);
var easeOut = new KeyframeEase(0.75, 85);
var easeDimensions = curProp.keyOutTemporalEase(curKeyIndex).length;
if(easeDimensions === 1)
curProp.setTemporalEaseAtKey(curKeyIndex, [easeIn], [easeOut]);
else if(easeDimensions === 2)
curProp.setTemporalEaseAtKey(curKeyIndex, [easeIn, easeIn], [easeOut, easeOut]);
else if(easeDimensions === 3)
curProp.setTemporalEaseAtKey(curKeyIndex, [easeIn, easeIn, easeIn], [easeOut, easeOut, easeOut]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment