AE ENHANCERS

Expressions/Scripts/Presets
It is currently Tue Jul 29, 2014 9:59 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Reverse Selected Layer Order script
PostPosted: Tue Jun 07, 2005 4:45 am 
Offline

Joined: Mon Jun 06, 2005 1:52 pm
Posts: 20
Location: Hengelo, Netherlands
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:
Code:
...
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:
Code:
...
   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.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 8:22 am 
Offline

Joined: Sat Dec 04, 2004 10:10 am
Posts: 36
erm.... in fact, you can do that with copy/paste... if you select your layers from the bottom ^^

_________________
http://www.shinjipierre.be/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 11:09 am 
Offline

Joined: Mon Jun 06, 2005 1:52 pm
Posts: 20
Location: Hengelo, Netherlands
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group