edited
// hide layer of certain color;
// 2023, use it at your own risk;
if (app.documents.length > 0) {
var theLayers = hideLayersOfColor ("orange");
if (theLayers.length > 0) {
alert (theLayers.join("\n"));
}
};
////// collect layers //////
function hideLayersOfColor (thisColor) {
// the file;
var myDocument = app.activeDocument;
// get number of layers;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if group collect values;
if (layerSet != "layerSectionEnd" /*&& layerSet != "layerSectionStart"*/ && isBackground != true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
var theColor = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("color")));
var theVisibility = layerDesc.getBoolean(stringIDToTypeID('visible'));
// var theBounds = layerDesc.getObjectValue(stringIDToTypeID("bounds"));
// var theseBounds = [theBounds.getUnitDoubleValue(stringIDToTypeID("left")), theBounds.getUnitDoubleValue(stringIDToTypeID("top")), theBounds.getUnitDoubleValue(stringIDToTypeID("right")), theBounds.getUnitDoubleValue(stringIDToTypeID("bottom"))];
if (theColor == thisColor) {
theLayers.push([theName, theIndex, theID, theColor, theVisibility]);
// hide layers;
if (theVisibility == true) {
var desc4 = new ActionDescriptor();
var list1 = new ActionList();
var ref1 = new ActionReference();
ref1.putIdentifier( stringIDToTypeID( "layer" ), theID);
list1.putReference( ref1 );
desc4.putList( stringIDToTypeID( "null" ), list1 );
executeAction( stringIDToTypeID( "hide" ), desc4, DialogModes.NO );
}
}
};
}
catch (e) {};
};
return theLayers
};