Count Layer issue

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

Moderators: Fahim, Distinct Sun, Víctor Paredes, erey, Belgarath, slowtiger

Post Reply
dkwroot
Posts: 659
Joined: Thu May 02, 2013 6:56 am
Location: USA
Contact:

Count Layer issue

Post by dkwroot » Sat Jan 16, 2016 10:35 am

I'm curious if anyone else is having trouble calling the "CountLayers" function.

local LayerNumber = moho.layer:CountLayers()

returns "CountLayers" is nill, despite the fact that there are several child layers to the selected group. This might be a bug, but I need some confirmation here.

--UPDATE--
The CountLayers function fails to work for group or bone layers, but appears to work for switch layers. I'm thinking this is a glitch now.
hayasidist
Posts: 2132
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Count Layer issue

Post by hayasidist » Sat Jan 16, 2016 12:42 pm

it's not "moho.layer" -- you need to recast the selected layer as a group

e.g.

Code: Select all

	local ctLayer
	local layer = moho:LayerAsGroup(moho.layer)

	if layer == nil then
--		error
	else
		ctLayer =  layer:CountLayers()
	end
is the glitch that switch "works" as not a group type!?
User avatar
synthsin75
Posts: 7127
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Count Layer issue

Post by synthsin75 » Sat Jan 16, 2016 8:33 pm

If you had previously done moho:LayerAsSwitch(moho.layer) it will be a proper group for counting layers. Otherwise the only bug would be switch layers always cast as group layers, which shouldn't harm anything.
dkwroot
Posts: 659
Joined: Thu May 02, 2013 6:56 am
Location: USA
Contact:

Re: Count Layer issue

Post by dkwroot » Sun Jan 17, 2016 4:34 am

Thanks guys, this helped a lot.
Post Reply