Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Adding a null to every comp creates infinityloop

  • Adding a null to every comp creates infinityloop

    Posted by Jacob Danell on February 22, 2014 at 1:07 pm

    I’m trying to create a script that adds an adjustment-layer to every comp and adds some effects and stuffs to it but first I’m trying to get the code straight. I have looked around and this is the code I find everywhere to make the script go trough all objects, if it’s a comp, add a null into that comp and continue but for me it ends up into an infinityloop and just adds nulls to the first comp it finds.

    If I change the code to alert me yes and no if the comp that is found is a CompItem it goes trough the search correctly and no infinityloop, so it seems like it gets stuck in the loop because the addNull();

    I have also tried to add “var myComp = null;” in the beginning and the end of the for-loop and the if statement but nothing worked.

    I don’t understand what’s wrong =/

    var myComp = null;
    for (var i = 1; i <= app.project.numItems; i++){
    if (app.project.item(i) instanceof CompItem){
    var myComp = app.project.item(i);
    myComp.layers.addNull();
    }
    }

    Jacob Danell replied 12 years, 2 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    February 22, 2014 at 5:39 pm

    Adding a null creates a new item in the Solids folder, so if you have a comp that appears after that folder in the list, its item number will keep getting bumnped, so it will get processed over and over.

    I’d harvest all the comps into an array first, then add the nulls:


    var myComps = [];
    for (var i = 1; i <= app.project.numItems; i++){
    if (app.project.item(i) instanceof CompItem){
    myComps.push(app.project.item(i));
    }
    }
    for (var i = 0; i < myComps.length; i++){
    myComps[i].layers.addNull();
    }

    Dan

  • Jacob Danell

    February 22, 2014 at 7:28 pm

    Ahhhh! I feel so stupid not thinking about it -.- Thanks!

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