How can I get a list of layers inside a group?

hi there, this is a recursive version of that script:

local vis = app.layer 
local visibility = vis.isVisible 
vis.isVisible = not visibility 

function goop(a)
	for _, layer in ipairs(a.layers) do 
		local visible = layer.isVisible
		if visible == visibility then 
			layer.isVisible = not visibility 
		end
		if layer.isGroup then 
			goop(layer) 
		end
	end
end 

if vis.isGroup then 
	goop(vis) 
end

what i do is checking if layer.isGroup and if it is, then i call the function from within itself again.

just one note though: if you plan to edit the stack of layers (for instance if you want to remove one or more of the layers), you need to put them into the table first and then iterate through that table. like in this example by dacap:

which reminds me i planned make recursive version of delete hidden layers… :E

2 Likes