Quantize Keyframes

What type of scripts do you need?

Moderator: byronnash

Post Reply
ahettinger
Posts: 13
Joined: March 5th, 2008, 11:48 am

I screwed the pooch by working in 29.97 in one comp and 30 in another. When I copied some layers over, their keyframes got shifted ever so slightly and it's really screwing me up. Now I have about 1000000 keyframes that I'm selecting one by one trying to line them up with the frames because they're like a small fraction of a frame off center.

Can someone with more scriptastic skills tell me how to make a script that will do this, or clue me in if there's one already out there? I already googled this to death.

Thanks!
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

Here's a simple example. It assumes that you want to quantize the opacity keyframes of the first layer in the active comp:

Code: Select all

var myComp = app.project.activeItem;
var myProperty = myComp.layer(1).property("opacity");
var myValue, myTime;

for (var i = myProperty.numKeys; i > 0; i --){
  myValue = myProperty.keyValue(i);
  myTime = Math.round(myProperty.keyTime(i)/myComp.frameDuration)*myComp.frameDuration;
  myProperty.removeKey(i);
  myProperty.setValueAtTime(myTime,myValue);
}

Dan
ahettinger
Posts: 13
Joined: March 5th, 2008, 11:48 am

Thanks this is great!
Post Reply