Skip to main content
Participating Frequently
September 2, 2021
Answered

How can i remove all the selected contents on several layers at once?

  • September 2, 2021
  • 3 replies
  • 1699 views

Hi all,

I'm working a hundred layers psd files, and i have to remove contents on several layers that out of my need.

So right now i'm using marquee selection tool to select my need part, then reverse it and manually remove all the unwanted content that in reversed selected on severial layers, one by one.

I wonder if there are any method that quickly remove all that selected contents on several layers at once?

Is there any script that help?

 

If you guys know or have any idea, please share with me.

 

Thank you.

 

Vuong Quoc

This topic has been closed for replies.
Correct answer jazz-y
quote

So right now i'm using marquee selection tool to select my need part, then reverse it and manually remove all the unwanted content that in reversed selected on severial layers, one by one.


By @ViXiMiXiV

 

a) create a selection in the document b) select the required layers on the layers palette c) run the script

@JJMack tried to explain, that layers may be different and the approach to removing content in them can be different, however, you said that we are talking about "normal layers" (I do not know what this means, but I assumed that these are pixel layers).
The script removes the content of only pixel layers. I added a check for the type of layer to the code so that you can safely select groups and layers of other types - it will simply ignore them.

 

var s2t = stringIDToTypeID;

(r = new ActionReference).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var lrs = executeActionGet(r).getList(p),
    sel = new ActionReference();

for (var i = 0; i < lrs.count; i++) {
    sel.putIdentifier(s2t('layer'), s = lrs.getReference(i).getIdentifier(s2t('layerID')));

    (r = new ActionReference).putProperty(s2t('property'), p = s2t('layerKind'));
    r.putIdentifier(s2t('layer'), s);
    if (executeActionGet(r).getInteger(p) == 1) {
        (r = new ActionReference).putIdentifier(s2t('layer'), s);
        (d = new ActionDescriptor()).putReference(s2t("target"), r);
        executeAction(s2t('select'), d, DialogModes.NO);
        executeAction(s2t('delete'), undefined, DialogModes.NO);
    }
}

(d = new ActionDescriptor()).putReference(s2t("target"), sel);
executeAction(s2t('select'), d, DialogModes.NO);

3 replies

Legend
September 2, 2021
var s2t = stringIDToTypeID;

(r = new ActionReference).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var lrs = executeActionGet(r).getList(p),
    sel = new ActionReference();

for (var i = 0; i < lrs.count; i++) {
    sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
    (r = new ActionReference).putIdentifier(s2t('layer'), p);
    (d = new ActionDescriptor()).putReference(s2t("target"), r);
    executeAction(s2t('select'), d, DialogModes.NO);
    executeAction(s2t('delete'), undefined, DialogModes.NO);
}

(d = new ActionDescriptor()).putReference(s2t("target"), sel);
executeAction(s2t('select'), d, DialogModes.NO);
ViXiMiXiVAuthor
Participating Frequently
September 3, 2021

Hi jazz-y,

Thank you for you script but nothing happen after i run this script.

 

Can you give a little bit more details on how (to make) it works? 

 

Vuong Quoc

Kukurykus
Legend
September 3, 2021

Did you make selection on the canvas?

JJMack
Community Expert
Community Expert
September 2, 2021

Photoshop has diffent kind of layers. Some layed kinds cans not be altered to remove part of its content by deleting pixels.  However, you could hide the area in all the selected layers with Masking.  That can be be scripted and have a shortcut..

JJMack
c.pfaffenbichler
Community Expert
Community Expert
September 2, 2021

»Some layed kinds cans not be altered to remove part of its content by deleting pixels.«

Good point. 

For Groups, Adjustment and Fill Layers one could check for Layer Masks and, if existing, fill with black, but what to do with Type Layers for example? 

Mylenium
Legend
September 2, 2021

One could probably cobble together a simple script that iterates through all layers and executes the delete command...

 

Mylenium

ViXiMiXiVAuthor
Participating Frequently
September 2, 2021

Thank for your kind reply...
It'd be good if i can find that script!

Vuong Quoc