Parsing folder-layers, a little help please.

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
rylleman
Posts: 750
Joined: Tue Feb 15, 2005 5:22 pm
Location: sweden
Contact:

Parsing folder-layers, a little help please.

Post 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
User avatar
synthsin75
Posts: 10280
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Post 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.
User avatar
rylleman
Posts: 750
Joined: Tue Feb 15, 2005 5:22 pm
Location: sweden
Contact:

Post by rylleman »

Alright, thank you! That did the trick.
Post Reply