Page 1 of 1

Parsing folder-layers, a little help please.

Posted: Fri Jan 23, 2009 12:11 pm
by rylleman
I'm working on a script that parses folder-type of layers for all it's child layers and I've got it partially working.

The following code works when running it on a Switch layer but on all other kind of folder-layers I get the lua-error;

Code: Select all

... attempt to call method 'CountLayers' (a nil value)
So, why does CountLayers() only work for switch-layers? and how can I get the folder parsing to work otherwise?

Code: Select all

local parent = moho.layer

local numberlayers = moho.layer:CountLayers()  --Here's the line lua has troubles with.
local j = 0

--parse through all child layers
for i= 0, numberlayers - 1 do

    moho:SetSelLayer (parent:Layer(j))
    print (moho.layer:Name())
    j =j+1

		end
	end

Posted: Fri Jan 23, 2009 1:20 pm
by synthsin75
moho.layer ia a generic layer object. You just need to tell it, explicitly, that you are wanting to treat that layer object as a group type layer (i.e switch, bone, group, particle).

Code: Select all

moho:LayerAsGroup(moho.layer):CountLayers()
That should work. :wink:

p.s. Also, that 'for' loop will do its own iteration through the layers. Just use 'i' instead of 'j' and you don't need to bother with that 'j' variable as all. The 'for' loop increments (1 by default) each cycle.

Posted: Fri Jan 23, 2009 1:35 pm
by rylleman
Alright, thank you! That did the trick.