Expressions/Scripts/Presets

Moderator: Paul Tuersley

 
Sebastian Moreno
Topic Author
Posts: 4
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: 4
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.
 
Sebastian Moreno
Topic Author
Posts: 4
Joined: Sat Nov 04, 2017 9:36 am
Location: Germany

Re: Delete Selected Keyframes via script

Wed Dec 20, 2017 7:19 am

I am struggling now with the layers. So it will delete all keyframes from all selected properties from selected layers.
AE deletes the selected keyframes form the first selected property from the first selected Layer--good until then :D. After that, looks like the selection goes to hell and is like nothing was selected in the fist place, so It can't move to the next selected property to continue deleting frames :shock:.

var layers = comp.selectedLayers; 
var properties = comp.selectedProperties;


for (var j = 0; j < layers.length; j++) {
  for (var k = 0; k < properties.length; k++) {

     if (properties[k] instanceof Property){

          var keySelection = property.selectedKeys; 

          for (var i = 0; i < keySelection.length; i++) {
          property.removeKey(keySelection[i]-i);   }
     }
}
}
 
beginUndoGroup
Posts: 80
Joined: Tue Nov 27, 2012 6:41 am

Re: Delete Selected Keyframes via script

Thu Dec 21, 2017 2:17 am

property is not defined in your snippet.

(You need define : var property = property[k])

Xavier

Who is online

Users browsing this forum: No registered users and 4 guests