How do you get a layer reference in another layer?

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
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

How do you get a layer reference in another layer?

Post by heyvern »

I'm trying to get my bone master thingy into one darn script...

I am not that good at this stuff... and I tend to... not do it for a while and forget my knowledge (Need space for Sea Quest reruns).

Anyway... I have a layer script for the master bone layer. I need to check the whole document for other bone layers with an extension... like

Code: Select all

controlled.ctrb
I am looking at 7feet's SwitchSlave script for inspiration (closest example I have) but it uses LayerAsSwitch... and there doesn't seem to be one of "those" for a bone layer... so... I don't have an example for how to apply my bone master "stuff" to the layers that are found.

I think I've got a handle on looping through the list and finding those layers and such... I just need to know what to assign to a variable when it finds those other matching layers. This should be an array as well since there could be a bunch of layers controlled by one master.

-vern
User avatar
Fazek
Posts: 246
Joined: Thu Apr 13, 2006 1:37 pm
Location: Hungary
Contact:

Post by Fazek »

Usually I am using the scheme below to scan over the layers:

Code: Select all

		-- recursive search for the source

			local stack= {}
			local sp= 0
			local document= moho.document

			for i= 0, document:CountLayers() - 1 do
				local layer= document:Layer(i)
				local parent= nil
				local sub= 0

				while true do

					if (layer:IsGroupType()) then
   --push onto the stack (there are sub-layers to scan)
						table.insert(stack, { parent, sub - 1 })
						sp= sp + 1
						parent= moho:LayerAsGroup(layer)
						sub= parent:CountLayers()
					end

   --here comes the main part, check the layer, recognise and modify its contents
  -- like: if (string.sub(layer:Name(),-15) == "controlled.ctrb") then ...

					if (something to recognise the layer) then
							-- do it here what you want 
					end

   --this is the stack administration

					if (sub > 0) then
						sub= sub - 1
						layer= parent:Layer(sub)
					else
						sub= -1

						while (sp > 0) do
							parent, sub= stack[sp][1], stack[sp][2]
							table.remove(stack)
							sp= sp - 1

							if (sub >= 0) then
								layer= parent:Layer(sub)
								break
							end
						end

						if (sub < 0) then
							break
						end
					end
				end
			end
By the way, what do you think about the news? The Anime Studio? How this will change our programming in Lua?
- - - Fazek
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Thanks for the code!

As far as the new version of "MohanimeProXP" and scripting... I have no idea.

I hope it doesn't change too much. I would like to think... if it aint broke... don't fix it... just add new stuff.;)

Hmm... I wonder though... will we have to change all the scripts references to "moho" to "anime"?

Easy enough with search and replace right?

I've seen other programs that had coding like this just leave the old references in there. Adobe Golive still has custom JS code that references "CS" when it use to be CyberStudio... they never bothered to change those variable names.

You can read my thoughts on the new name in the "Lookout Flash" thread in the general forum.

-vern
Post Reply