MohoDoc:CountLayers()

Version added: before 9.5

Return value:

int32 the number of top-level layers in the document
An example of its use is:
local i
local doc = moho.document
local ct = doc:CountLayers()

for i = 0, ct-1 do
	local layer = doc:Layer(i)	
	Print (layer:Name())
end


This prints the names of all the top level layers (i.e. it does not print the names of layers contained in group type layers)


Note also that it is possible to avoid the use of local variables for ct and the MohoDoc and MohoLayer classes thus:

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


This is more compact, but if the program needs to make many references to (e.g.) data items within Layer(i) the first option layer = doc:Layer(i) is preferable.
<< Back to MohoDoc