Expressions/Scripts/Presets

Moderator: Paul Tuersley

 
w_m0zart
Topic Author
Posts: 20
Joined: Mon Jun 06, 2005 1:52 pm
Location: Hengelo, Netherlands
Contact:

Reverse Selected Layer Order script

Tue Jun 07, 2005 4:45 am

I just made a script which reverses the order of selected layers.
It is just a little variation on the Reverse Layer Order, but with an extra selection option. Now it's possible to select these layers which have to be reversely ordered.

The difficult part was to find out that layers in a selection appear in an order, which depend on the order they have been selected. If we do not sort the index from these layers, the reordening proces could easily give a mess.

Originally I wrote:
...
for(j = 1; j <= length; j++)  // collect in array SNA all layers which should be reordered
{
   SNA[j]=myComp.selectedLayers[j-1].index;
}

for(j = 1; j < length; j++)   // sort elements ascending; SNA[1] holds lowest value
{
   pL=length;
   do
   {
      if (SNA[j]>SNA[pL])     // swap elements to get lowest of this pair first
      {
         w=SNA[pL];
         SNA[pL]=SNA[j];
         SNA[j]=w;
      }
   } while (--pL > j);
}
...

Later on I found ECMAScript contains already a method to sort arrays. So I modified the code to:
...
   function comparefn(x, y) {return x - y;}
...
   function reverseSelectedLayerOrder(myComp){
      var comp_layers = myComp.layers;
      var length    = myComp.selectedLayers.length;

      var SNA    = new Array();
      var pL;
      var w;

      if (length > 1)          // only process 2 or more selected layers
      {
         for(j = 0; j < length; j++)   // collect in array SNA all layers which should be reordered
         {
            SNA[j]=myComp.selectedLayers[j].index;
         }

         SNA=SNA.sort(comparefn);   // sort elements ascending; SNA[0] holds lowest value
...


The script may be downloaded from the following location:

http://www.nijdam.de/aescripts/ReverseSelectedLayerOrder.zip
Last edited by w_m0zart on Sat Apr 08, 2006 4:47 am, edited 4 times in total.
 
Shinjipierre
Posts: 36
Joined: Sat Dec 04, 2004 10:10 am

Tue Jun 07, 2005 8:22 am

erm.... in fact, you can do that with copy/paste... if you select your layers from the bottom ^^
 
w_m0zart
Topic Author
Posts: 20
Joined: Mon Jun 06, 2005 1:52 pm
Location: Hengelo, Netherlands
Contact:

Tue Jun 07, 2005 11:09 am

I think you mean the order in which the layers have been selected, will determine in which way they will be pasted. With this script it doesn't matter in which way they are selected. Regardless of its selection order, they will be always reversely ordered after running the script.

Who is online

Users browsing this forum: No registered users and 2 guests