Copy link to clipboard
Copied
Hey
I load in photoshop 20 layers. As I load them I'd like to check if a layer has any RGB value or its just pure black, I guess it could be done via levels but not sure.
In any case how can I check if active layer has a color value in it? Then if there is just black I can just delete the layer.
I guess I would also like to check if newly created channel with color in it also has data in it.. I know if its black and when I try to CTRL+Click to select I will get a warning that channel is empty and nothing can be selected... I guess is how can I capture that check and get a true/false result out of it.
Regards
Dariusz
Message was edited by: Dariusz Makowski
Copy link to clipboard
Copied
Hi Dariusz,
Try this Code..
Special thanks to c.pfaffenbichler
-yajiv
#target "photoshop"
$.level=2;
function GetLayerValue(CHN){
var myDocument = app.activeDocument;
var theHistograms = new Array;
var theResults = new Array;
for (var m = 0; m < CHN; m++) {
var thisHisto = myDocument.channels[m].histogram;
var theCheck = false;
var theNumber = 0;
// check for the first non-zero value;
while (theCheck == false) {
if (thisHisto[theNumber] > 0) {
theCheck = true;
var thisNumber = (255 - theNumber) * 100 / 255;
theResults.push (Math.round(thisNumber));
};
theNumber++
};
theHistograms.push(myDocument.channels[m].histogram);
};
return theResults;
}
var docRef = app.activeDocument;
var layerRef = docRef.artLayers;
var theNumber = docRef.layers.length-1;
for (var m = theNumber; m >= 0;m--){
LayerVisible(docRef);
var theLayer = docRef.layers[m];
if (theLayer.typename == "ArtLayer"){
theLayer.visible=true;
if (app.activeDocument.mode == DocumentMode.CMYK) {
var Colvalue= GetLayerValue(4)
theLayer.visible=false;
alert("Alert!\nLayer Name : "+theLayer.name +"\nColor value : "+Colvalue);
if(Colvalue[0]==0 && Colvalue[1]==0 && Colvalue[2]==0 && Colvalue[3]>0){
alert(theLayer.name +" layer have pure black value");
}
}
if (app.activeDocument.mode == DocumentMode.RGB) {
var Colvalue= GetLayerValue(3);
theLayer.visible=false;
alert("Alert!\nLayer Name : "+theLayer.name +"\nColor value : "+Colvalue);
if(Colvalue[0]==0 && Colvalue[1]==0 && Colvalue[2]==0){
alert(theLayer.name +" layer have pure black value");
}
}
}
}
function LayerVisible(docRef){
var l=docRef.layers.length
while(l--){
docRef.artLayers.visible=false;
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now