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
ViXiMiXiVAuthor
Participating Frequently
September 2, 2021

Thank you for your reply,

My files almost normal layer with brushes, i can manually select those layers one by one and del... 
The point is to reduce file size and remain only needed parts so Masking is not an option to me...

 

Vuong Quoc

 

JJMack
Community Expert
Community Expert
September 2, 2021

Deleting details in a raster layers will not reduce the size of saved layered file size to a any great extent. Deleting  and merging layers may reduce file size quite a bit. . Some layers have high overhead like embedded smart object layers contain as copy of an Image file the can be  a huge  layered file. With fewer Layers Photoshop will also perform better. You cans target several layers and drag them to the trash.

A 4TB external disk is not expensive these days.  All you may gain with smaller files may be a little I/O time opening and saving files. Larger uncompressed file may save you some  processing time spent  compressing and decomplessing data..

JJMack
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