-
play a number of specified keyframes on a layer
Hello,
I’ve dabbled in letting ChatGPT write an expression for me that does, what I’m looking for in this posts topic, but sadly, no amount of coaxing gets the AI to write code that does the job. Can anyone here help me out? What’s wrong with this code?
// Set the range of keyframes to play
var startKeyframe = 1; // Change this value to the index of the first keyframe you want to play
var endKeyframe = 5; // Change this value to the index of the last keyframe you want to play
// Calculate the total duration of the keyframe range
var rangeDuration = key(endKeyframe).time – key(startKeyframe).time;
// Calculate the time offset for each keyframe
var timeOffset = rangeDuration / (endKeyframe – startKeyframe);
// Calculate the time of the outpoint of the layer
var outpoint = thisLayer.outPoint;
// Calculate the start time of the keyframe range
var startTime = outpoint – rangeDuration;
// Loop through the keyframes in the range and set their values at the corresponding times
for (var i = startKeyframe; i <= endKeyframe; i++) {
var keyframeTime = startTime + (i – startKeyframe) * timeOffset;
valueAtTime(keyframeTime);
}