// show red layers, hide the other layers; // 2016, use it at your own risk; #target photoshop if (app.documents.length > 0) { // the file; var myDocument = app.activeDocument; // get number of layers; var ref = new ActionReference(); 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; var theOthers = 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 not layer group collect values; if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) { var theName = layerDesc.getString(stringIDToTypeID('name')); var theID = layerDesc.getInteger(stringIDToTypeID('layerID')); var visible = layerDesc.getBoolean(stringIDToTypeID("visible")); var theColor = layerDesc.getEnumerationValue(stringIDToTypeID("color")); if (typeIDToStringID(theColor) == "red") {theLayers.push([theName, theID])} else {theOthers.push([theName, theID])} }; } catch (e) {}; }; // show red layers; for (var m = 0; m < theLayers.length; m++) { showLayer (theLayers[1], false); }; // hide others; for (var n = 0; n < theOthers.length; n++) { showLayer (theOthers[1], true); }; }; ////// show layer ////// function showLayer (theID, showOrHide) { if (showOrHide == false) {var idHd = charIDToTypeID( "Shw " )} else {var idHd = charIDToTypeID( "Hd " )}; var desc2 = new ActionDescriptor(); var idnull = charIDToTypeID( "null" ); var list1 = new ActionList(); var ref1 = new ActionReference(); ref1.putIdentifier(charIDToTypeID( "Lyr " ), theID); list1.putReference( ref1 ); desc2.putList( idnull, list1 ); executeAction( idHd, desc2, DialogModes.NO ); }; |