Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Layer Order Script

  • Layer Order Script

    Posted by Evan Schafer on March 28, 2007 at 7:26 pm

    Hello-

    I was wondering if anyone had a link to a script that would reorder my layers based on their X position. I am trying to animate 80 red dots popping up individually to indicate branch locations of a bank and the client wants them to animate across the state from left to right. Trouble is, they are not in order now and I figured that a script could easily do this. Anyone have a script that could acheive this? Thanks.

    Lloyd Alvarez replied 19 years, 1 month ago 3 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    March 28, 2007 at 8:42 pm

    This seems to work:

    var myComp = app.project.activeItem;

    var myLayer;
    var myLayerArray = [];
    myLayerArray[0] = myComp.layer(1);
    var gotIt;

    for (var i = 2; i <= myComp.numLayers; i++){ myLayer = myComp.layer(i); gotIt = false; for (var j= 0; j < myLayerArray.length; j++){ if (myLayer.property("position").value[0] < myLayerArray[j].property("position").value[0]){ myLayerArray.splice(j,0,myLayer); gotIt = true; break; } } if(! gotIt) myLayerArray[myLayerArray.length] = myLayer; } myLayerArray[0].moveToBeginning(); for (var i = 1; i < myLayerArray.length; i++){ myLayerArray[i].moveAfter(myComp.layer(i)); } Dan

  • Evan Schafer

    March 29, 2007 at 1:13 pm

    Worked like a champ. Muchas gracias!

  • Lloyd Alvarez

    March 31, 2007 at 2:30 pm

    Hey Dan,

    Is there a way to make this script work with selected layers instead of all the layers in a Comp?

  • Dan Ebberts

    April 1, 2007 at 6:17 am

    Lloyd,

    Would the layers need to end up in the same slots? I mean, if you selected layers 3,6,7, and 9, would the sorted layers need to be in those slots?

    Dan

  • Lloyd Alvarez

    April 12, 2007 at 2:00 pm

    Interesting.. I hadnt considered that. I would probably select layers in a group without a break between the layer order, but I guess if i selected in a weird order it would be good if they ended up in the same slots..

  • Lloyd Alvarez

    April 12, 2007 at 2:00 pm

    Interesting.. I hadnt considered that. I would probably select layers in a group without a break between the layer order, but I guess if i selected in a weird order it would be good if they ended up in the same slots..

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