Delete just the first few keyframes out of many?

Hello,

I’ve created a simple automation that loops through just the first few keyframes of the Opacity property of a layer.

I am able to select the first few Opacity keyframes and move the Time indicator to each keyframe and even change the value of just those keyframes via the automation. So I know the conditional on the loop is working.

However if I try to delete just the first few keyframes (using the delete key Action), no matter what conditional is set for how many keyframes it should do, ALL the keyframes get deleted. I even tried using a custom menu command (Clear) to delete the selected keyframes and again, ALL the keyframes get deleted.

If I place a message to appear in the loop, it appears as expected, the number of times constrained by the conditional. But if I simply add a delete key line to the loop, the message will ignore the conditional and keep appearing until all the keyframes are deleted.

Could you create an automation that deletes just, say, the fiirst 2 keyframes of the Opacity property of a layer so I can see what I might be doing wrong?

I’m running AE 2020. AT = 1.0.3.8

Thanks for a great product!

1 Like

Hi @NoBones, welcome to the forum and thanks for posting this question as it will help other users as well!
Thanks for the detailed information, this problem seems like a bug but is a mistake in your conditional, I am guessing you are checking for the “index” property of the keyframe, it sounds like it’s the right way to do it and it’s working many times but for deleting keyframes this approach won’t work as expected.

Example:
let’s say you want to delete only the first keyframe, you loop on all the keyframes and check if the index is equal to “1” , then delete this keyframe.
this loop will delete all the keyframes because every time you will delete a keyframe all the indexes of all the other keyframes will update and change, so after deleting the first keyframe the next keyframe index will be “1” as well because now it is the first key(so all the keyframes will be removed).

When deleting keyframes or layers or any other object you shouldn’t use the index to specify which object you want to delete, this problem exist in all the delete/remove actions, you need to find other property that won’t be changed after removing the keyframe, there are many ways you can delete only the first 2 keyframes:

  1. you can create a number variable(set to 1) before the loop and use this number as the index of the keyframe, and each time add 1 to the number variable, in this way the index will remain correct after deleting keyframes, use this variable in your conditional instead of the “index” property .
    delete keys 01.json (9.0 KB)

  2. you can delete the keyframes by their “time” property, first loop over all the keyframes and save to a variable the time of the 2nd keyframe, then loop again and check if the keyframe “time” property <= to the variable value, then remove that keyframe.
    delete keys 02.json (11.6 KB)

Hope the examples helped you understand how it works, please let me know if you need further explanation,
Thanks,
Alon

1 Like

Ah! You’re exactly right. I was using the index.

That makes perfect sense Alon. I should have realized that.

Thank you so much for your response and examples!