Page 1 of 1

Problem with GroupLayer and CountLayers()

Posted: Wed Mar 23, 2016 11:02 am
by lehtiniemi
I'm trying to go through all layers in the document, but in the code below, after detecting a IsGroupType() and trying to read the layer count, I get "attempt to call method 'CountLayers' (a nil value). What am I doing wrong here?

I have three layers in my document: A group layer, a bone layer and a normal layer. At index 1 my script prints: i=1, "Bone layer at 1" but then the error when I try to read the layer count. All IsGroupType()-layers should have CountLayers() because their parent class is GroupLayer, right?

Code: Select all

	for i = 0, moho.document:CountLayers()-1 do
		local currentLayer = moho.document:Layer(i)

		if (currentLayer:LayerType() == MOHO.LT_GROUP) then print ("Group layer at ", i) end
		if (currentLayer:LayerType() == MOHO.LT_BONE) then print ("Bone layer at ", i) end
		if (currentLayer:LayerType() == MOHO.LT_PARTICLE) then print ("Particle layer at ", i) end
		if (currentLayer:LayerType() == MOHO.LT_SWITCH) then print ("Switch layer at ", i) end

		if (currentLayer:IsGroupType()) then
			print ("Group layer found at index ", i, ", layer count is ", currentLayer:CountLayers())
		end
	end

Re: Problem with GroupLayer and CountLayers()

Posted: Wed Mar 23, 2016 1:13 pm
by synthsin75
You need to cast the layer as a group type first.

local group = moho:LayerAsGroup(layer)

group:Countlayers()

Re: Problem with GroupLayer and CountLayers()

Posted: Wed Mar 23, 2016 1:28 pm
by lehtiniemi
synthsin75 wrote:You need to cast the layer as a group type first.

local group = moho:LayerAsGroup(layer)

group:Countlayers()

Thank you!!!!