2 Replies Latest reply on Dec 7, 2016 11:31 AM by Jarda Bereza

    Delete Hidden Layers Even When Using Clipping

    iamwickedtall1 Level 1

      I am running the following script to delete hidden layers:

          for(var i = 0 ; i < app.activeDocument.layers.length;i++){
              currentLayer = app.activeDocument.layers[i];
              if(currentLayer.visible == false) {
              currentLayer.allLocked = false;
              currentLayer.remove();
              }
          }
      

       

      I realized however, that it does not take into consideration, if it has anything clipped to it, via clipping mask.

       

      For example(below), if I delete hidden layers via this method Layer 1 gets deleted, and Layer 5 becomes visible, which unintended.

      Is there a way to traverse clipped layers and delete them as well? Or is there a way to call the photoshop menu item "Delete Hidden Layers" which removes Layer 1 and it's clipped layers?

        • 1. Re: Delete Hidden Layers Even When Using Clipping
          Chuck Uebele Adobe Community Professional & MVP

          You can test if a layer is clipped another layer by:

           

          if(currentLayer.grouped){alert('This layer is clipped')}
          

           

          Note, it will not tell you if the layer you want to delete has clipped layers. What you will have to do is find your current layer and then select the layer above it to test to see if it's clipped to the lower layer.

          1 person found this helpful
          • 2. Re: Delete Hidden Layers Even When Using Clipping
            Jarda Bereza Level 4

            You can run this command from script:

            2016-12-07_201120.jpg

             

            It delete also cliped layers. (All layers in document must be unlocked and it works only with whole document)

             

            I also did some similar script which removes all layers with zero size/pixels/text-string inside. Even if they are visible. And I solved same Issue like you. Magic scripts for Photoshop  (Delete empty layers faster v1.0) Anyway this script is focused to performance and code is hard to read and understand if you compare it with original Adobe script with slow recursive loop and slow DOM approach.

             

            If layer is empty(invisible) and will be deleted it goes index above until there are cliped layers. It creates array of cliped layers and this array is merged with array where are layers to hide. I am hiding/deleting all layers in one step(not one by one) because of big performance diference. (line 333 and 288)

             

            You also can have layer clipped to hidden folder since CS6.