Problem with GroupLayer and CountLayers()
Posted: Wed Mar 23, 2016 11:02 am
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?
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