Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Randomize Layer Order

  • Caleb Armstrong

    December 14, 2009 at 6:01 pm

    This is what I have:

    {
    var myComp = app.project.activeItem;
    var n = myComp.numLayers;
    var myLayers = [];
    var myIdx = [];
    for (var i = 1; i
    myIdx[i-1] = i;
    myLayers[i-1] = myComp.layer(i);
    }

    var idx;
    var temp;
    for (var i = 0; i
    idx = i + Math.floor(Math.random()*(myIdx.length – i));
    temp = myIdx[i];
    myIdx[i] = myIdx[idx];
    myIdx[idx] = temp;
    }
    for (var i = 0; i
    myLayers[myIdx[i]-1].moveToBeginning();
    }
    }

    As I mentioned, this is my first experiment in trying to use a script, so I’m sure that I’m not implementing it correctly but I figured I’d ask about the script first.

    Thanks again.

    point9@gmail.com

  • Dan Ebberts

    December 14, 2009 at 6:09 pm

    You didn’t pick up the full text of the for loop statememts (lines 6, 13 and 19). That sometimes happens because the less-than character ( < ) gets interpreted as html. Let's try it again: { var myComp = app.project.activeItem; var n = myComp.numLayers; var myLayers = []; var myIdx = []; for (var i = 1; i <= n; i++){ myIdx[i-1] = i; myLayers[i-1] = myComp.layer(i); } var idx; var temp; for (var i = 0; i < myIdx.length; i++){ idx = i + Math.floor(Math.random()*(myIdx.length - i)); temp = myIdx[i]; myIdx[i] = myIdx[idx]; myIdx[idx] = temp; } for (var i = 0; i < myIdx.length; i++){ myLayers[myIdx[i]-1].moveToBeginning(); } } Dan

  • Caleb Armstrong

    December 14, 2009 at 6:24 pm

    Odd. I’m using Firefox and those characters aren’t getting picked up. I fired up Safari and was able to see the full code.

    Now it works great. Awesome. Thank you so much!

    point9@gmail.com

  • Jim Branstetter

    July 25, 2010 at 12:43 am

    hi Dan,

    Found this thread but I think I missed something, where do you put this script.

    In other words I’m kind of dense, Could you start at the beginning (the most basic as I’m not that great with expressions, getting better though) for me.

    Thanks in advance, Jim

    Jim Branstetter
    RubberBulletStudio.com

  • Jim Branstetter

    July 25, 2010 at 12:53 am

    hi Dan,

    Found this thread but I think I missed something, where do you put this script.

    In other words I’m kind of dense, Could you start at the beginning (the most basic as I’m not that great with expressions, getting better though) for me.

    Thanks in advance, Jim

    Jim Branstetter
    RubberBulletStudio.com

  • Dan Ebberts

    July 25, 2010 at 7:09 am

    Jim,

    This is a script, not an expression. So you save it somewhere as a .jsx file and then execute it in After Effects by File > Scripts > Run Script File.. (and then navigate to the script).

    Dan

  • Jim Branstetter

    July 25, 2010 at 8:05 pm

    Thanks Dan

    Jim Branstetter
    RubberBulletStudio.com

  • Sam Gregory

    February 21, 2011 at 10:43 am

    Hi Dan,

    I’ve used this script in CS5 an I’m getting this error;

    Unable to execute script at line 7.
    Expected: ;

    any Ideas?

    Many thanks

  • Dan Ebberts

    February 21, 2011 at 5:59 pm

    Are you talking about the first script in this thread? I just tried it in CS5 and it works fine for me. Try just copying it from my post and pasting it directly into the script editor, then run it and see what happens.

    Dan

  • Sam Gregory

    February 21, 2011 at 9:59 pm

    Yes the first one you posted. Thanks the reply, Dan. I have copied directly into the script editor and ran it, typed it in text editor and saved it’s as a .jsx nothing is working. I think, maybe it’s because I’m running over a server, adobe products never work great over server.

    Any ideas would be great. It would be great to not have to do it the long way round.

Page 2 of 4

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