Copy link to clipboard
Copied
I want to hide all layers ( inside subgroups) if the name start with "vis_"
This works with specific layer names, I tried to adapt with indexOf, no luck...
function toggleVisibility(layerName) {
var desc11 = new ActionDescriptor();
var idnull = stringIDToTypeID("null");
var list6 = new ActionList();
var ref8 = new ActionReference();
var idlayer = stringIDToTypeID("layer");
ref8.putName(idlayer, layerName);
list6.putReference(ref8);
desc11.putList(idnull, list6);
var desc = new ActionDescriptor()
var ref = new ActionReference();
var idlayer = stringIDToTypeID("layer");
ref = new ActionReference();
ref.putName(idlayer, layerName);
var desc = executeActionGet(ref);
var vis = desc.getBoolean(charIDToTypeID("Vsbl"));
var idhide = stringIDToTypeID("hide");
executeAction(idhide, desc11, DialogModes.NO);
}
toggleVisibility('Layer 1');
Please comment out or delete the line
app.activeDocument.activeLayer = curLay;
and replace the line beginning with
if(curLay.name.indexOf ...
with this line:
if( (curLay.name.indexOf("vis_") >= 0) && (curLay.typename != "LayerSet") ){
Hi, the modified script works fine, thank you!!
iterLayers(app.activeDocument);
function iterLayers(l) {
for(var i=0; i<l.layers.length; i++) {
var curLay = l.layers[i];
// app.activeDocument.activeLayer = curLay;
if(curLay.typename == "LayerSet") {
iterLayers(curLay);
} else {
if( (curLay.name.indexOf("vis_") >= 0) && (curLay.typename != "LayerSet") ){
curLay.visible = false;
}
}
}
}
Copy link to clipboard
Copied
Screenshots of the layers panel (before/after) and or a sample PSD file is always helpful to illustrate.
Copy link to clipboard
Copied
This does the job:
iterLayers(app.activeDocument);
function iterLayers(l) {
for(var i=0; i<l.layers.length; i++) {
var curLay = l.layers[i];
app.activeDocument.activeLayer = curLay;
if(curLay.typename == "LayerSet") {
iterLayers(curLay);
} else {
if(curLay.name.indexOf("vis_") >= 0) {
curLay.visible = false;
}
}
}
}
Copy link to clipboard
Copied
GNDGN, thank you but...
although script hides the correct layers, it is relativeli slow and breaks all other layers visibility !
Copy link to clipboard
Copied
Could you provide a sample file?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Please comment out or delete the line
app.activeDocument.activeLayer = curLay;
and replace the line beginning with
if(curLay.name.indexOf ...
with this line:
if( (curLay.name.indexOf("vis_") >= 0) && (curLay.typename != "LayerSet") ){
Copy link to clipboard
Copied
Hi, the modified script works fine, thank you!!
iterLayers(app.activeDocument);
function iterLayers(l) {
for(var i=0; i<l.layers.length; i++) {
var curLay = l.layers[i];
// app.activeDocument.activeLayer = curLay;
if(curLay.typename == "LayerSet") {
iterLayers(curLay);
} else {
if( (curLay.name.indexOf("vis_") >= 0) && (curLay.typename != "LayerSet") ){
curLay.visible = false;
}
}
}
}
Copy link to clipboard
Copied
But, it is relatively slow at my original psd
Code using the ActionDescriptor usually is much faster
If any one can improve the script I will be grateful
Copy link to clipboard
Copied
What about the UXP way?:
const app = require('photoshop').app;
iterLayers(app.activeDocument);
function iterLayers(l) {
l.layers.forEach(ls => {
if(ls.layers != undefined) {
iterLayers(ls);
} else {
if(ls.name.indexOf("vis_") >= 0) {
ls.visible = false;
}
}
});
}
Copy link to clipboard
Copied
@Stephen Marsh
Hi, sample PSD is uploaded.
The script from GNGN working fine but it is relatively slow, running 3- 5 sec to at original psd
Action Manager code is usualy faster, but I cannot find or edit a script to do the job
Thank you all
Copy link to clipboard
Copied
Another approach here, I think a little bit faster
https://community.adobe.com/t5/photoshop-ecosystem-discussions/a-script-to-toggle-a-named-layer-or-g...