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

  • Randomize Layer Order

    Posted by Rhett Robinson on July 4, 2008 at 7:04 pm

    This is really more a request for a script, or at least a starting point. In my searches I saw that this topic has been raised several times, but never found a resolution.

    Here’s the question: I end up with several hundred (yes, sometimes thousands) of still images, and need to randomize the order of the layers prior to pasting my keyframe setup and sequencing the layers. Ideally, I could run the script… don’t like the order? Run the script again. Any assistance or direction would be appreciated.

    Dan Ebberts replied 10 months, 1 week ago 13 Members · 36 Replies
  • 36 Replies
  • Dan Ebberts

    July 5, 2008 at 5:35 pm

    Try this:

    {
    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

  • Rhett Robinson

    July 5, 2008 at 8:58 pm

    You are the MAN! This is light years ahead of what I was trying from looking at a javascript guide.

    I also wanted to thank you for your motionscript.com website. Although admittedly I don’t necessarily understand everything on there, I’ve certainly learned a lot, and had a WHOLE lot of fun combining different expressions and attaching everything I could to expression control effects.

    This is EXACTLY what I needed, and it’s greatly appreciated.

  • Jason Brown

    January 9, 2009 at 4:45 am

    Dan,

    I was able to use this script…very nice! I’m still very much a beginner with scripts and expressions, but I love every time I get one to work for me!

    One question…is there a way to randomize the in-point of several layers? I’m currently setting the length to 1 frame…sequencing layers and doing it in segments of 20…and, after using your script…it gives a decent randomness to the in point of a layer, just wondering if there is an easier way?

    -Jason

  • Dan Ebberts

    January 9, 2009 at 5:10 am

    Play around with this:

    {
    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[i].outPoint = myComp.frameDuration; myLayers[i].startTime = (myIdx[i]-1)*myComp.frameDuration; } } Dan

  • Jason Brown

    January 9, 2009 at 5:47 am

    YOU ARE THE MAN!

    Worked perfectly…

    Do you have a paypal account I could contribute to? That saved me a ton of time!

    Is there a way to constrict the varying in points to randomize within a period of 20 frames?

    -Jason

  • Dan Ebberts

    January 9, 2009 at 6:33 am

    >Is there a way to constrict the varying in points to randomize within a period of 20 frames?

    I’m having trouble picturing what you mean. Wouldn’t that leave gaps? Or do you mean you want the first 20 layers to be randomly distributed in the first 20 frames, the second 20 layers in the second 20 frames, etc?

    Dan

  • Jason Brown

    January 9, 2009 at 9:50 am

    I’m actually saying that in 20 frames…100 layers-inpoint would be distributed randomly. Obviously, there would be duplicate start times of some of the layers…but if it’s random, then they wouldn’t pop on in a consecutive manner.

    Basically, I have a screen full of boxes with space in between…looks like a grid. But I want each box to pop on *randomly* so I’m using the script you gave me to randomize the in point, but it needs to happen quicker. All layers need to come on in about 20-30 frames.

    I’ve actually solved the issue, I just pre-comped it and ran it at accelerated speed so it happens quicker. So I’ve found a workaround, but I’d like to gain a better understanding of it.

    Thanks so much for your help!

    -Jason Brown

  • Dan Ebberts

    January 9, 2009 at 4:30 pm

    It seems like you could do it with something like this:

    {
    var myComp = app.project.activeItem;
    for (var i = 1; i <= myComp.numLayers; i++) { myComp.layer(i).startTime = Math.floor(Math.random()*20)*myComp.frameDuration; } } Dan

  • Caleb Armstrong

    December 14, 2009 at 4:35 pm

    This is my first experience with scripts. I have over one hundred photos that I’m making into a slideshow for a client. I am using CS4. I tried using the above script but am not having luck with it. I am getting an “Expected: ;” error and when I debug in the javascript editor it tells me that the error(s) start on line 7 myIdx[i-1] = i;

    Will this script run in CS4? If not, how can I alter it so that it will?

    Thanks for the help.

    cheers.

    point9@gmail.com

  • Dan Ebberts

    December 14, 2009 at 4:50 pm

    It should work fine with AE CS4. Did you copy and paste it directly from the thread above?

    Paste what you used back here and I’ll see if I can figure out what happened.

    Dan

Page 1 of 4

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