Key Frame Stretching Script only affect 1 layer
Good moring guys, I'm trying to script that would stretch out the distance between my selected keyframes proportionately, similar to alt click and dragging but faster.
Here's the feature I want for the script:
1. It would stretch out from the point of the last keyframe
2. It would reselect the keyframes, so that you could stretch it again if you needed
3. I want it to affect every keyframe I selected from different layers.
I got 1 and 2 to work but can't find a solution for 3
var comp = app.project.activeItem;
if (comp != null && (comp instanceof CompItem)) {
var layer = comp.selectedLayers[0];
if (layer != null) {
var keys = layer.selectedProperties;
if (keys.length > 0) {
app.beginUndoGroup("Stretch Keyframes");
var stretchFactor = 0.8; // Change this to your desired stretch factor
var keyData = [];
for (var i = 0; i < keys.length; i++) {
for (var j = 1; j <= keys[i].numKeys; j++) {
var keyTime = keys[i].keyTime(j);
var keyValue = keys[i].keyValue(j);
var inTemporalEase = keys[i].keyInTemporalEase(j);
var outTemporalEase = keys[i].keyOutTemporalEase(j);
var inInterpolationType = keys[i].keyInInterpolationType(j);
var outInterpolationType = keys[i].keyOutInterpolationType(j);
keyData.push({property: keys[i], keyTime: keyTime, keyValue: keyValue, inTemporalEase: inTemporalEase, outTemporalEase: outTemporalEase, inInterpolationType: inInterpolationType, outInterpolationType: outInterpolationType});
}
while (keys[i].numKeys > 0) {
keys[i].removeKey(1);
}
}
for (var i = 0; i < keyData.length; i++) {
var lastKeyTime = keyData[keyData.length - 1].keyTime;
var newKeyTime = lastKeyTime + (keyData[i].keyTime - lastKeyTime) * stretchFactor;
var newKeyIndex = keyData[i].property.addKey(newKeyTime);
keyData[i].property.setValueAtTime(newKeyTime, keyData[i].keyValue);
keyData[i].property.setTemporalEaseAtKey(newKeyIndex, keyData[i].inTemporalEase, keyData[i].outTemporalEase);
keyData[i].property.setInterpolationTypeAtKey(newKeyIndex, keyData[i].inInterpolationType, keyData[i].outInterpolationType);
keyData[i].property.setSelectedAtKey(newKeyIndex, true);
}
app.endUndoGroup();
} else {
alert("No properties are selected.");
}
} else {
alert("No layer is selected.");
}
} else {
alert("No composition is selected.");
}Is there's a way for it to loop around all the layers selected?
Thank you!
