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

Hello, dear community! I trying to learn Aseprite API. I want to iterate through all layers in my sprite.
I found a great solution from Olga_Galvanova

However, I noticed this algorithm doesn’t go into a group layer. How I can fix it?
I’ve tried to use app.command.OpenGroup() but doesn’t work for me

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

Thank you! It’s literally that I want

1 Like