Activity › Forums › Adobe After Effects Expressions › Remove all keyframes by script
-
Remove all keyframes by script
Posted by Xavier Gomez on July 10, 2013 at 9:21 pmHello,
is there a way to remove all keyframes on a given property other than using the removeKey() method ?
I’m thinking about the timeVary stopwatch : from off to on it adds a keyframe (same as addKey()), from on to off it removes them all in a fraction of millisecond, while a removeKey() loop can be very slow.
So: is that stopwatch on —> off accessible to scripting?Thank you for any suggestion.
Xavier
Eric Peel replied 2 years, 3 months ago 6 Members · 7 Replies -
7 Replies
-
Mitch Mann
July 10, 2013 at 10:44 pmMaybe have the script select all keys on the property, then delete. You could call delete as a menu command. Then you wouldn’t have to loop.
-
Xavier Gomez
July 11, 2013 at 9:46 amThank you, it works very well. Deletion is instant!
Make sure that the property (and no other) is selected, that the property has keys, then app.executeCommand(21) remove all its keys instantly.
Xavier.
-
Xavier Gomez
July 11, 2013 at 4:21 pmHello again, i’m facing another problem.
Just found out that 21 is a dangerous command (!) and better be sure to have focus on the right thing before using it. For instance, running app.executeCommand(21) while the focus is on the project panel will delete all currently selected project items, which is obviously not what was intended.Is there a way to know that the right composition is opened in the Timeline Panel, and not just selected in the project one ? This to make sure that it’s content will be targetted by delete, not the comp itself.
I’ve read this thread https://forums.creativecow.net/thread/227/23479#24437 which deals with this problem but i don’t fully understand it, and I would like to avoid CS6 only abilities such as setActive(). Unlike in the cited thread i know exactly which comp to focus on but i really can’t find what string to use for app.findMenuCommand(…).
Thank you for advice.
Xavier.
-
Mike Sevigny
July 4, 2016 at 3:58 pmThis is one of the first things to come up for removing keyframes so I thought I would share a few methods
First identify the parameter with the keyframes:
targetComp = app.project.activeItem; // Collect the active composition
selectedLayer = targetComp.selectedLayers; // Collect the selected layers
targetParam = selectedLayer[0].transform.position; // Target the Position parameter of the first selected layer
Then you can cycle forward through the keyframes and delete them:
while (targetParam.numKeys != 0) { // While there are still Keyframes, cycle through them
targetParam.removeKey(1); // Delete the first Keyframe
}
or cycle backward and delete them:
for (i = targetParam.numKeys; i != 0; i--) { // Cycle through the Keyframes
targetParam.removeKey(i); // Remove the current Keyframe
}Mike Sevigny
https://www.torusfx.com -
Cole Bo
July 25, 2018 at 3:57 pmI’m a bit late to the party (only 5 years). But using a combination of 2 shortcuts (select all keyframes then delete them) it can be done. Not sure if this is what you’re looking for, but it may come in handy!
1) Select the layer(s)
2) Push the U key (This will reveal all keyframes on the selected layers)
3) Push Ctrl + Alt + A (This will highlight all keyframes that are showing)
4) Delete (This will delete all selected keyframes)There is another one for deleting expressions as well. I use this for compositions I’ve duplicated and no longer want the expressions on. So instead of going through and deleting each expression individually:
0) Assuming all layers inside the composition are collapsed before doing this
1) Select the layer(s)
2) Push the E key twice (Known as EE) (This will also reveal all expressions within the layers selected)
3) Push Ctrl + Alt + A (This will highlight all keyframes that are showing)
4) Push Alt + Shift + = (This will delete all expressions)
5) If you want to get rid all the effects too (Slider expressions or anything else)
6) Ctrl + Shift + E (Deletes all effects)Hope this helps!
-
Eric Peel
February 19, 2024 at 9:20 pmI’m very late (6 years to your comment and 11 to the OP) But anyway, your first series of shortcuts only works for the keyframes literally visible in the timeline window. If you have more than about 50 layers, or a small enough window, this isn’t the best solution.
The best GUI approach I’ve found to delete keyframes of all layers would be:
1. Select All.
2. Reveal them (t for opacity for example).
3. Click the stopwatch button.
4. Repeat 2-3 for each property.The best scripting approach seems to be to create a loop cycling through the layers, a sub loop(s) cycling through the properties and using app.executeCommand(21) on each, as Xavier says. Best to create an undo group for this. I don’t see any reason why this is “dangerous”. It’s just the delete command. It saves a lot of time to delete all keyframes at once rather than deleting them last to first. And the undo group adds safety.
To marginally speed things up, disable rendering for the script with:
app.suppressRender = true;
//code
app.suppressRender = false;
Reply to this Discussion! Login or Sign Up