FORUMS: list search recent posts

Delete Selected Keyframes via script

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Sebastian Moreno
Delete Selected Keyframes via script
on Dec 20, 2017 at 6:31:40 pm
Last Edited By Sebastian Moreno on Dec 20, 2017 at 7:06:50 pm

Hi all
I am writing a script to remove keyframes from selected properties and layers.

with this code (below) AE deletes the selected keyframes form the first selected property from the first selected Layer good until then :D.

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


As i said, it deletes the selected keys from the first property 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.

here is the complete code I have:

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); }
}
}
}


any help, suggestion or advice is welcome


Return to posts index

Walter Soyka
Re: Delete Selected Keyframes via script
on Dec 20, 2017 at 7:10:59 pm

When deleting items from an array, start at the end and work backwards to the beginning; otherwise, the indices change as you go!

Walter Soyka
Designer & Mad Scientist at Keen Live [link]
Motion Graphics, Widescreen Events, Presentation Design, and Consulting
@keenlive [twitter]   |   RenderBreak [blog]   |   Profile [LinkedIn]


Return to posts index

Sebastian Moreno
Re: Delete Selected Keyframes via script
on Feb 1, 2018 at 11:04:37 am

Hi Walter
I am stuck.

I tried looping backwards for everything, one by one (all first, or comp and the property and vice-versa) nothing seemed to work. Just forwards and as you said the index changes.
To see If i am doing something wrong I tried removing layers something super basic:

for ( var i = selectedLayers.length ; i != 0 ; i--) {
selectedLayers[i].remove();
}

and also

for ( var i = selectedLayers.length ; i > 0 ; i--) {
selectedLayers[i].remove();
}

This does not work. Is after having a bug ? IT WORKS when operand i =1 and of course it wont remove one of the selected.

any ideas why is this happening when looping backwards.


Return to posts index


Walter Soyka
Re: Delete Selected Keyframes via script
on Feb 1, 2018 at 11:23:54 am

selectedLayers is an array with an origin of zero. If selectedLayers.length = 3, then the only valid indices are selectedLayers[0], selectedLayers[1] and selectedLayers[2]. That means the starting value and the test in your loops are both off by one.

Try this:

app.beginUndoGroup("Remove selected layers");

selectedLayers = app.project.activeItem.selectedLayers;
for (var i = selectedLayers.length - 1 ; i >= 0 ; i--) {
selectedLayers[i].remove();
}

app.endUndoGroup();


Walter Soyka
Designer & Mad Scientist at Keen Live [link]
Motion Graphics, Widescreen Events, Presentation Design, and Consulting
@keenlive [twitter]   |   RenderBreak [blog]   |   Profile [LinkedIn]


Return to posts index

Sebastian Moreno
Re: Delete Selected Keyframes via script
on Feb 5, 2018 at 8:41:56 pm

Hi Walter
Thank you so much. That worked wonderfully, Indexes are now doing good. Still after I delete the key-frames of a property the selection is lost.


for (var x = selectedLayers.length - 1; x >= 0; x--) {

var currentLayer = selectedLayers[x];
var SelectedProp = currentLayer.selectedProperties;

for (var i = SelectedProp.length - 1; i >= 0; i--) {

var currentProp = SelectedProp[i];
var keySelection = currentProp.selectedKeys;

for (var k = keySelection.length - 1; k >= 0; k--) {

currentProp.removeKey(keySelection[k]);
}
}
}

Any ideas what may be the issue


Return to posts index

Mark Whitney
Re: Delete Selected Keyframes via script
on Dec 20, 2017 at 10:19:38 pm

Just so you aren't re-inventing the wheel, you might want to check out the suite of free scripts at the Redefinery, this one in particular:

// rd_RemoveKeys.jsx
// Copyright (c) 2006-2013 redefinery (Jeffrey R. Almasol). All rights reserved.
// check it: http://www.redefinery.com
//
// Name: rd_RemoveKeys
// Version: 3.0
//
// Description:
// This script displays a palette with controls for removing keyframes from
// the selected layers.

Details of the usage on some of these:







Return to posts index


Sebastian Moreno
Re: Delete Selected Keyframes via script
on Dec 21, 2017 at 1:54:53 pm

Thank you Mark
I checked the script, I love how he approaches the issue. But there is no selected keys option. That is why I am doing it.

I will try what Walter said, hopefully it will work for all selected keyframes no matter how many properties and layers are selected.

Thanks!!


Return to posts index

Mark Whitney
Re: Delete Selected Keyframes via script
on Dec 21, 2017 at 6:32:38 pm

Ah dang. Ya, the rd_ script works only on the selected Layers but no option to select just a particular property(s).

Sounds like ya got a very useful script in the works.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]