Expressions/Scripts/Presets

Moderator: Paul Tuersley

 
Sebastian Moreno
Topic Author
Posts: 2
Joined: Sat Nov 04, 2017 9:36 am
Location: Germany

Delete Selected Keyframes via script

Sat Nov 04, 2017 10:04 am

Hi everyone, 
I am a still beginner at Extendscript. How could I store selected keyframes so I can delete them afterwards. I have tried arrays but I am missing something. This is the simplified version:

var keySelection = property.selectedKeys; 

for (i = keySelection[0]; i < keySelection.length; i++) {
property.removeKey(i)
}

I am writing a script that will move keys to a specific time in milliseconds,secs or frames.. the button is aware of the comp frame-rate and you would be able to move to the selected keys to a typed specific time

Thanks,
Sebastian
 
jordanwade33
Posts: 13
Joined: Mon Dec 08, 2014 11:11 pm

Re: Delete Selected Keyframes via script

Mon Nov 06, 2017 4:22 pm

I think what you were going for is this:
var keySelection = property.selectedKeys; 
for (i = 0; i < keySelection.length; i++) {
    property.removeKey(keySelection[i]);
}

The problem with that is that as you're removing keyframes, the current indexes of the keyframes reduce by one, but your original keySelection indexes stay the same. The way you can get around that is to subtract the number of times you've already removed a keyframe:
var keySelection = property.selectedKeys; 
for (i = 0; i < keySelection.length; i++) {
    property.removeKey(keySelection[i]-i);
}
 
Sebastian Moreno
Topic Author
Posts: 2
Joined: Sat Nov 04, 2017 9:36 am
Location: Germany

Re: Delete Selected Keyframes via script

Thu Nov 09, 2017 6:45 am

Hi Jordan
That did the trick.So good to know this, no idea that the indexes stay the same, because apparently  ae deselects after deleting a keyframe. 
Thanks a lot.

Who is online

Users browsing this forum: No registered users and 9 guests