Sorting Layers

Upload Photoshop Scripts, download Photoshop Scripts, Discussion and Support of Photoshop Scripts

Moderators: Tom, Kukurykus

antonio1

Sorting Layers

Post by antonio1 »

Hi,

I really need a sorting layers, in this way I found this forum. I had a look over but I didn't find anything here but I found between my other e-books some examples not very good because there was in low, very low speed. So I worked hard to find a solution. Below you can find my first photoshop script doing what I want, sorting layers in descending order.

What I'd like is to improve it, I'd like to increase the speed, and if it's possible to add a working bar, or a stop watch to count any improve.

If someone could help I'll be happy to discuss and develop this script.

Code: Select all//layers order by....

// sort the layers by name in descending order
layerNames=[];
originalLayers = [];
var NumLayers=app.activeDocument.layers.length;
Window.alert("you have "+NumLayers+" layers");
for (var i=0; i<NumLayers; i++){
layerNames = app.activeDocument.layers.name;
originalLayers = layerNames;
   };

for (var x=0; x<NumLayers; x++){   
      for (var y=0; y<NumLayers-1; y++){ 
            if (layerNames[y].toUpperCase() < layerNames[y+1].toUpperCase()){
               var pilot = layerNames[y+1];
             layerNames[y+1]=layerNames[y];
             layerNames[y]=pilot;       //sorted layerNames
      }
      }
   }
var s=0;
for (var m=0; m<NumLayers; m++){
      for (var n=0; n<NumLayers; n++){
               if (layerNames[m] == originalLayers[n]){
            app.activeDocument.layers[n].move(app.activeDocument.layers[s], ElementPlacement.PLACEBEFORE);
              s++;
              for (var i=0; i<NumLayers; i++){
                  originalLayers = app.activeDocument.layers.name;
               }
            }
         }
   }
Window.alert("Finish your sorting!");


regards,
antonio1
Patrick

Sorting Layers

Post by Patrick »

Hi Antonio, welcome to the forum. Adding a progress bar and a timer would be pretty easy, I will post an example of that in your script this afternoon.

Regarding making it faster, I don't have any suggestions off the top of my head. I havent ran your script though, I will give it a look and see if anything comes to mind.

Looks pretty good for your first script!

Patrick