3 Replies Latest reply: Feb 15, 2011 5:11 PM by phosphorspitter RSS

    Delete all Numbered Layers

    phosphorspitter Community Member

      I got this script gere from Cpfaffenbichler and ned to change it to Delete All Numbered Layers. I tries to change all appaerances of hide to delete but it will not work.

      Couls some one please write it the correct way?

      I did not include a number-check  but only identified them by their names starting with »Layer «, still  you could give this a try:

       

       

      // 2010, use at your own risk;

      #target photoshop

      if (app.documents.length > 0) {

        hideLayers(app.activeDocument);

        };

      ////// function to hide all pixel-layers //////

      function hideLayers (theParent) {

      if (!allLayers) {var allLayers = new Array}

      else {};

      for (var m = theParent.layers.length - 1; m >= 0;m--) {

      var theLayer = theParent.layers[m];

      // apply the function to layersets;

          if (theLayer.typename == "ArtLayer") {

            if (theLayer.name.slice(0, 6) == "Layer ") {

              theLayer.visible = false;

              };

            allLayers.push(theLayer)

            }

          else {

            allLayers = allLayers.concat(hideLayers(theLayer))

            }

          };

        return allLayers

        };

        • 1. Re: Delete all Numbered Layers
          Michael L Hale Community Member

          It is better not to try and delete the layers while you are searching for them. Doing so changes the layer's index. The code below finds the layers first then removes the found layers. Note adapted from the code posted. Removes layers with a name that starts with 'layer ' so may not remove all layers with numbers in the name.

           

          // 2010, use at your own risk;
          #target photoshop
          if (app.documents.length > 0) {
               var numberedLayers = hideLayers(app.activeDocument);
               for(var l=0;l<numberedLayers.length;l++){
                    numberedLayers[l].remove();
               }
          };
          ////// function to find all pixel-layers with names that start with Layer //////
          function hideLayers (theParent) {
               if (undefined == allLayers) var allLayers = new Array;
               for (var m = theParent.layers.length - 1; m >= 0;m--) {
                    var theLayer = theParent.layers[m];
                    // apply the function to layersets;
                    if (theLayer.typename == "ArtLayer") {
                         if (theLayer.name.slice(0, 6) == "Layer ") {
                              allLayers.push(theLayer)
                         }
                    }
                    else {
                    allLayers = allLayers.concat(hideLayers(theLayer))
                    }
               }
               return allLayers
          };
          
          • 2. Re: Delete all Numbered Layers
            phosphorspitter Community Member

            Thank you very much. I will be very

            busy over Valentines Weekend but will gi

            ve a try by Tuesday and will report back.

            Stay tuned

            • 3. Re: Delete all Numbered Layers
              phosphorspitter Community Member

              Works perfect. Does what I needed.

              Thank you very much.