Sorting Layers

Upload photoshop scripts, download photoshop scripts, discussion and support of photoshop scripts

Moderator: PS-Moderators

Sorting Layers

Postby antonio1 » Wed Oct 07, 2009 9:29 pm


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
originalLayers = [];
var NumLayers=app.activeDocument.layers.length;
Window.alert("you have "+NumLayers+" layers");
for (var i=0; i<NumLayers; i++){
layerNames[i] = app.activeDocument.layers[i].name;
originalLayers[i] = layerNames[i];

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]=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);
              for (var i=0; i<NumLayers; i++){
                  originalLayers[i] = app.activeDocument.layers[i].name;
Window.alert("Finish your sorting!");

Posts: 1
Joined: Wed Oct 07, 2009 11:16 am

Postby Patrick » Fri Oct 09, 2009 2:04 pm

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!

Photoshop CS4 / JavaScript / Windows XP
Posts: 780
Joined: Thu May 11, 2006 3:36 am
Location: Missouri, USA

Return to Photoshop Scripts

Who is online

Users browsing this forum: No registered users and 1 guest