1 Reply Latest reply on Oct 7, 2010 5:45 PM by Michael L Hale

    moving artLayers within a group


      So I have a bunch of layers within a group and I'd like to organize them in a predefined order.  For example, if there's a group with the following layer names "D"," A", "C" I want the script to reorder it to "A", "C", "D". 


      I know there's a function called move that used ElementPlacement but it requires knowing what to place before/after it.  In this particular case, I might not know all the layers that are within the group so I wouldn't know what to place it before/after without doing a whole bunch of if statements.  Any ideas?

        • 1. Re: moving artLayers within a group
          Michael L Hale Level 5

          Read the layer names into an array then use the arrays sort method to sort the files. Then order the layers using that array. Something like this...



          var layers = app.activeDocument.artLayers;// for top level layers, change if sorting layerSet
          var layerNames = [];
          for(var l =0;l<layers.length;l++){
          for( l =1;l<layers.length;l++){
              var topLayer = app.activeDocument.artLayers.getByName(layerNames[l-1]);