• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Delete Hidden Layers Even When Using Clipping

Enthusiast ,
Dec 06, 2016 Dec 06, 2016

Copy link to clipboard

Copied

I am running the following script to delete hidden layers:

    for(var i = 0 ; i < app.activeDocument.layers.length;i++){

        currentLayer = app.activeDocument.layers;

        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?

TOPICS
Actions and scripting

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Dec 06, 2016 Dec 06, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 07, 2016 Dec 07, 2016

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines