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

Script that finds and removes all black layers.

Participant ,
Jul 02, 2021 Jul 02, 2021

Copy link to clipboard

Copied

Hello,

I am looking for a script that can locate and delete all black layers in PS.

 

Layerstack.JPG

 

I don't know how to write Javascript, and I can't find any thread explaining how to do this.

I am looking for something that is similar to "Delete All Empty Layers" script, but that finds black layers instead.

 

Thank you for taking your time,

 

Tsu-tey

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

correct answers 2 Correct answers

LEGEND , Jul 02, 2021 Jul 02, 2021

 

sTT = stringIDToTypeID; function tggl() {
	(ref = new ActionReference()).putIdentifier(sTT('layer'), idntfr);
	(lst = new ActionList()).putReference(ref); (dsc = new ActionDescriptor())
	.putList(sTT('null'), lst), dsc.putBoolean(sTT('toggleOptionsPalette'), true)
	executeAction(sTT('show'), dsc)
}

lrs = [].slice.call((aD = activeDocument).artLayers)
wh = aD.width * aD.height; while(lrs.length)
	idntfr = (shft = lrs.shift()).id, tggl(),
	blck = aD.histogram[0] == wh,
	tggl(), blck && shft.rem
...

Votes

Translate

Translate
Valorous Hero , Jul 03, 2021 Jul 03, 2021

Give an example. Upload your PSD file.

Noticed that scripts (mine and yours) remove the black layer if there is one RGB pixel (0,0,1) in it, which is wrong. Corrected my script

 

// important, the active layer must not have to be a group. 

var inv = false; // depends on channels settings. true = masked areas, false = selected areas. check what you have.


var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("count"));
r.putEnumerated(stringIDToTypeID("lay
...

Votes

Translate

Translate
Adobe
Participant ,
Jul 02, 2021 Jul 02, 2021

Copy link to clipboard

Copied

This works perfectly for me.

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
Participant ,
Jul 02, 2021 Jul 02, 2021

Copy link to clipboard

Copied

Thank you!

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