Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Random Layer distribution in 3D space

  • Random Layer distribution in 3D space

    Posted by Pascal Greuter on February 7, 2007 at 6:48 pm

    Hi

    I’m new into this great forum and my first question is about expressions (sorry for my bad english but I’m from switzerland).

    I have about 50 layers that i would randomly distribute in 3D space.
    For that i have created a null object (called “Center”) and then added the following expression to the layers:

    xVal = thisComp.layer(“Center”).transform.position[0]+random(-10000, 10000);
    yVal = thisComp.layer(“Center”).transform.position[1]+random(-10000, 10000);
    zVal = thisComp.layer(“Center”).transform.position[2]+random(-10000, 10000);
    [xVal,yVal,zVal]

    Basically, it does what I want but only for the first frame. Because of the random command, it calculates a new position at every frame and that’s not what i need. The main goal is, that I don’t need to position 50 layers manually. The layers won’t be animated, they sould only be distributed do a random position.

    I hope anyone out there understands what I mean and can give me a hint. Thank you very much.

    Regards,
    Pascal

    Elias Huch replied 10 years, 9 months ago 7 Members · 9 Replies
  • 9 Replies
  • Dan Ebberts

    February 7, 2007 at 7:12 pm

    Just add this to the front of your expression:

    seedRandom(index,true)

    Dan

  • Dan Ebberts

    February 7, 2007 at 7:14 pm

    Ooops, left off the semicolon:

    seedRandom(index,true);

  • Pascal Greuter

    February 7, 2007 at 9:54 pm

    Dan, many thanks! That helped. Absolutlely fantastic!!!

    Regards, Pascal

  • Lloyd Alvarez

    February 8, 2007 at 5:04 pm

    Hey Pascal,

    Since expressions are calculated every frame for every layer, i found that doing a 3D layer distribution with expressions was fairly slow. So i wrote a script that does the same thing, but without the every frame overhead of expressions. Hope it’s useful to you.

    -Lloyd

    //
    //
    //3D Layer Distributor by Lloyd Alvarez (July 2006)
    //
    //Distributes layers in 3D space within set ranges..
    //
    //
    //
    //

    clearOutput();
    app.beginUndoGroup(“3D Layer Distributor”);

    // Set Range parameters here: [min,max]

    var set_X = [0,2500];
    var set_Y = [0,200];
    var set_Z = [0,-2000];

    var myComp = app.project.activeItem;
    var selectedLayers = myComp.selectedLayers;

    for (var i = 0; i < selectedLayers.length; i++) { var myLayer = selectedLayers[i]; var x = 0; var y = 0; var z = 0; x = Math.random() * (set_X[1]-set_X[0]); y = Math.random() * (set_Y[1]-set_Y[0]); z = Math.random() * (set_Z[1]-set_Z[0]); myLayer.property("Position").setValue([x,y,z]); } writeLn("Distributed " + selectedLayers.length + " Layers"); app.endUndoGroup();

  • Tim Berthiaume

    September 9, 2009 at 8:47 pm

    Fantastic script – really appreciate you posting this.

    It worked perfectly for my needs, and for someone who has very little experience with scripts, it was nice to have it work properly out of the box.

    I adjusted the script so that it randomized the “Anchor Point” – leaving the “postion” animations I had created intact.

    Saved me lots of time! Thanks Again!

  • Barry Suydam

    January 19, 2012 at 2:59 pm

    I have used this script many times…well done Lloyd. I was hoping it could be modified to do the same thing for the layers 3d rotation by changing the words position to rotation but no good..any ideas?

  • Dan Ebberts

    January 19, 2012 at 3:26 pm

    Try changing this:

    myLayer.property(“Position”).setValue([x,y,z]);

    to this:

    myLayer.property(“X Rotation”).setValue(x);
    myLayer.property(“Y Rotation”).setValue(y);
    myLayer.property(“Z Rotation”).setValue(z);

    Dan

  • Matt Exton

    November 20, 2014 at 10:33 am

    Hi Lloyd,

    I know this post was from a while ago and things have changed a lot since then but I was wondering how I could apply your above script into CS6 on a mac? Do I need to “install” into a scripts folder or copy and paste it somewhere into AE? Apologies, I’m daily new to scripts / expressions.

    Kind Regards,
    Matt

  • Elias Huch

    July 14, 2015 at 4:07 pm

    What I did is Duplicated another script file (.jsx) from inside the script folder (Applications/After Effects/Scripts) in text edit. Replaced all of the text in that file with the script info above. Then saved it into the scripts folder. That did the trick.

    Elias Huch
    Motion Graphics Designer
    Reelvizion Productions

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