Hello! I'm wondering if you can help me write up a very quick script. It's similar to the aescripts jdSmartBaker, but much simpler.
I need a script that looks at the first keyframe and then continually deletes each keyframe after it that has the same value, until it hits a keyframe with a new value. Then, it repeats the same thing from that key frame. This would allow me to bake a stair-stepped animation, and then delete the unnecessary in-between keyframes to have it effectively "tween" the animation between the steps.
For example, an animation with 15 keyframes like this:
1, 1, 1, 1, 1, 1.5, 1.5, 1.5, 1.5, 2, 2, 2, 2, 2, 3,
Would become an animation with just 4 keyframes like this:
1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.625, 1.75, 1.875, 2, 2.2, 2.4, 2.6, 2.8, 3
Any help is much appreciated!
Delete Duplicate Keyframes
Moderator: byronnash
-
- Posts: 704
- Joined: June 5th, 2004, 7:59 am
- Location: London, UK
Try this:
Code: Select all
var activeItem = app.project.activeItem;
if (activeItem != null && activeItem instanceof CompItem) {
var selectedProps = activeItem.selectedProperties;
var y;
app.beginUndoGroup("Remove Duplicate Keys");
for (var x = 0; x < selectedProps.length; x++) {
if (selectedProps[x].numKeys > 1) {
y = 1;
while (y < selectedProps[x].numKeys) {
if (selectedProps[x].keyValue(y).toString() == selectedProps[x].keyValue(y+1).toString()) {
selectedProps[x].removeKey(y+1);
} else {
y ++;
}
}
}
}
app.endUndoGroup();
}