Copy link to clipboard
Copied
I know there are many threads about deleting hidden layers but my insight seems not deep enough to cobble it together for layers inside a selected group *only* ...
Suppose I've already selected only one Group manually or by action step.
This group will have no nested groups.
I'd now like a script that deletes any hidden layer — only within the selected group.
Thank you for any help!
Try a new version
var a= activeDocument.activeLayer
if(a.typename == "LayerSet")
for(var i = a.layers.length - 1; i >= 0; i--)
a.layers[i].visible || a.layers[i].remove()
-Manan
For a single step undo try the following
activeDocument.suspendHistory("removeHiddenLayer", "removeHiddenLayer()")
function removeHiddenLayer()
{
var a= activeDocument.activeLayer
if(a.typename == "LayerSet")
for(var i = a.layers.length - 1; i >= 0; i--)
a.layers[i].visible || a.layers[i].remove()
}
P.S. :- I have never manipulated history in PS and am new to PS scripting as well, based on my exp with InDesign scripting(that is what i do mostly) manipulating history could sometimes cause
...Copy link to clipboard
Copied
Hi there,
Try the following code
var a= activeDocument.activeLayer
if(a.typename == "LayerSet")
for(var i = 0; i < a.layers.length; i++)
a.layers[i].visible || a.layers[i].remove()
-Manan
Copy link to clipboard
Copied
Thanks! Very compact but it does not fully work...
It seems to always work when there is just one invisible layer.
When there are more, it depends where they are.
An example where it fails is if I use 4 layers inside the group and the two middle ones are invisible. It will then delete only the first invisible one.
P.S. I'm only using like 5 simple pixel and adjustment layers trying it out..
Copy link to clipboard
Copied
It seems the problem occurs only when two or more consecutive layers are invisible.
Doesn't work for ...
invisible
invisible
visible
visible
Works ...
invisible
visible
invisible
visible
Copy link to clipboard
Copied
Try a new version
var a= activeDocument.activeLayer
if(a.typename == "LayerSet")
for(var i = a.layers.length - 1; i >= 0; i--)
a.layers[i].visible || a.layers[i].remove()
-Manan
Copy link to clipboard
Copied
That seems perfect!
Thank you very, very much, Manan! Have a great weekend 🙂
P.S.
When you Undo step by step, one of the invisible layers will now be visible. No problem to me — just a warning for other users.
Copy link to clipboard
Copied
For a single step undo try the following
activeDocument.suspendHistory("removeHiddenLayer", "removeHiddenLayer()")
function removeHiddenLayer()
{
var a= activeDocument.activeLayer
if(a.typename == "LayerSet")
for(var i = a.layers.length - 1; i >= 0; i--)
a.layers[i].visible || a.layers[i].remove()
}
P.S. :- I have never manipulated history in PS and am new to PS scripting as well, based on my exp with InDesign scripting(that is what i do mostly) manipulating history could sometimes cause issue. So please do test to be certain all works fine with this code snippet
-Manan
Copy link to clipboard
Copied
That works fine! Thank you again, Manan! 🙂