Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions for loop to remove all layers in a comp.

  • for loop to remove all layers in a comp.

    Posted by Fabio Apelbaum on December 31, 2015 at 7:19 pm

    Hi guys, some help will be appreciated! This one should be very simple.

    Im writing a very simple for loop to go over a comp to remove all layers.

    for(var i = 1; i <= app.project.item(1).layers.length; i++){

    app.project.item(1).layer(i).remove();

    };

    The problem I am having is that for some reason, it only removed layer 1, 3 and 5 leaving inside the comp layers 2 and 4…. it is the first time I use the .remove() inside a for loop, could you please let me know what am I doing wrong? the same for loop works fine with any other tasks I tried such as hide all visible layers, etc. Its only with the remove(), not sure if its a bug or something i am doing wrong…

    Thanks!

    Fabio

    Dan Ebberts replied 10 years, 7 months ago 2 Members · 1 Reply
  • 1 Reply
  • Dan Ebberts

    December 31, 2015 at 8:55 pm

    Removing an indexed object changes the indices of all the downstream objects. So I usually run the loop backwards, like this:


    for(var i = app.project.item(1).numLayers; i > 0; i--){
    app.project.item(1).layer(i).remove();
    }

    Dan

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy