-
Error on script, function selectedProperty.key is undefined
Wondering if anyone can help me understand what is wrong with this script?
var activeComp = app.project.activeItem;
if (activeComp == null || !(activeComp instanceof CompItem)) {
alert("Please select a composition first.");
} else {
var selectedLayer = activeComp.selectedLayers[0];
if (selectedLayer == null) {
alert("Please select a layer first.");
} else {
var selectedProperty = selectedLayer.selectedProperties[0];
if (selectedProperty == null) {
alert("Please select a property first.");
} else if (selectedProperty.numKeys < 2) {
alert("Property must have at least 2 keyframes.");
} else {
var lastKeyframeIndex = selectedProperty.numKeys.lastIndex;
var secondToLastKeyframeIndex = selectedProperty.numKeys - 1;
// Store the last keyframe value and temporal ease
var lastKeyframe = selectedProperty.key(lastKeyframeIndex);
var lastValue = lastKeyframe.value;
var lastTemporalEase = lastKeyframe.temporalEase;
// Set the second-to-last keyframe value and temporal ease to the last keyframe value and temporal ease
var secondToLastKeyframe = selectedProperty.key(secondToLastKeyframeIndex);
secondToLastKeyframe.setValue(lastValue);
secondToLastKeyframe.setTemporalEaseAtKey(1, lastTemporalEase);
// Remove the last keyframe
selectedProperty.removeKey(lastKeyframeIndex);
}
}
}when I run it I get the following error:
Unable to execute script at line 20. Function selectedProperty.key is undefined.Thanks in advance.