Forums › Adobe After Effects Expressions › Apply ease to selected keyframes using scripting
-
Apply ease to selected keyframes using scripting
-
Andrew Sherman
February 28, 2023 at 12:31 pmI have a script that is not quite working yet; I want to apply easing to any selected keyframes, on any selected properties. Can you help me see where I’m going wrong?
// Get the currently selected layer
var selectedLayer = app.project.activeItem.selectedLayers[0];
// Get the selected properties on the layer
var selectedProperties = selectedLayer.selectedProperties;
// Define easing
var easeSlow = [new KeyframeEase(0, 90)];
// Loop through the selected properties
for (var i = 0; i < selectedProperties.length; i++) {
// Get the selected keyframes on the property
var selectedKeyframes = selectedProperties[i].selectedKeys;
// Apply easing to each selected keyframe
for (var j = 0; j < selectedKeyframes.length; j++) {
var keyframeIndex = selectedKeyframes[j];
selectedProperties[i].setTemporalEaseAtKey(keyframeIndex, easeSlow, easeSlow);
}
} -
Filip Vandueren
February 28, 2023 at 3:12 pmHaven’t checked, but I think it’s because of the square brackets around your newly created Ease-object. Try:
var easeSlow = new KeyframeEase(0, 90);
-
Andrew Sherman
March 1, 2023 at 10:49 amI’ve updated this now and it works nicely on things like opacity and separated position dimensions. I know how to update it to work for arrays (eg for scale), I just have not done that yet. However, When I try to run this easing script on something like keyframes on an effect slider, it gives me an error “undefined is not an object”. Do you know how I can get this to work for effect properties as well? It’s working correctly easing transform properties, but not effect properties.
// Get the selected properties
var selectedProperties = app.project.activeItem.selectedProperties;
// Define easing
var easeSlow = new KeyframeEase(0, 90);
// Loop through the selected properties
for (var i = 0; i < selectedProperties.length; i++) {
// Get the selected keyframes on the property
var selectedKeyframes = selectedProperties[i].selectedKeys;
// Apply easing to each selected keyframe
for (var j = 0; j < selectedKeyframes.length; j++) {
var keyframeIndex = selectedKeyframes[j];
selectedProperties[i].setTemporalEaseAtKey(keyframeIndex, [easeSlow], [easeSlow]);
}
}
Log in to reply.