Keyframes in swithlayer

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
maxic
Posts: 64
Joined: Wed Sep 22, 2004 8:24 am
Location: Moscow, Russian Federation
Contact:

Keyframes in swithlayer

Post by maxic »

As in LUA to receive quantity keyframes in swithlayer and their values?
User avatar
maxic
Posts: 64
Joined: Wed Sep 22, 2004 8:24 am
Location: Moscow, Russian Federation
Contact:

Post by maxic »

Now I use such decision

Code: Select all

local switchLayer = moho:LayerAsSwitch(moho.layer) 
local countF=moho.document:EndFrame()
for i = 0, countF - 1 do
        local curentF=switchLayer:SwitchValues():GetValue(i)
        if (curentF~=switchLayer:SwitchValues():GetValue(i-1) or i==0)then
            print (i.." "..switchLayer:SwitchValues():GetValue(i))
        end
end
But it is not pleasant to me, and not so correctly works
Last edited by maxic on Thu Dec 16, 2004 3:19 am, edited 1 time in total.
User avatar
maxic
Posts: 64
Joined: Wed Sep 22, 2004 8:24 am
Location: Moscow, Russian Federation
Contact:

Post by maxic »

How to define quantity of keys, I have understood

Code: Select all

local switchLayer = moho:LayerAsSwitch(moho.layer)
print (switchLayer:SwitchValues():CountKeys())
It is impossible to define in what frames there are keys
myles
Posts: 821
Joined: Sat Aug 21, 2004 3:32 am
Location: Australia, Victoria, Morwell
Contact:

Post by myles »

Hello Maxic,

have a look at this script, partly derived from your code.

Unfortunately, it still involves stepping through frame by frame.

It doesn't handle sub-groups within Switch layers, but that would be possible to add without too much extra code

Only tested on a couple of simple files.

Regards, Myles.
"Quote me as saying I was mis-quoted."
-- Groucho Marx
User avatar
7feet
Posts: 840
Joined: Wed Aug 04, 2004 5:45 am
Location: L.I., New Yawk.
Contact:

Post by 7feet »

Oh, the usefulness, thanks to you both. It cleared up a few things for me on iterating through layers. I was working on a color picker, and unfortunately I couldn't find an easy way to do it. So I figured I would just scan through the layers in depth order looking for a shape under the mouse. I didn't really think of using the

Code: Select all

local currentLayer = moho.document:Layer(i)
that you used. I'm still a little dim at this. What I did do

Code: Select all

	local originalLayer = moho.layer
	for i =  moho.document:CountLayers() - 1, 0, -1 do
		local mesh = moho:Mesh()
		moho:SetSelLayer(moho.document:Layer(i))
		moho:UpdateUI()
		moho:UpdateSelectedChannels()
		local mesh = moho:Mesh()
		if (moho.layer:LayerType() == MOHO.LT_VECTOR) then
			print ("Layer number:", i+1,"Layer name:",moho.layer:Name(),"Shapes:",mesh:CountShapes())
		else
			print ("layer", i+1,moho.document:Layer(i):Name())
		end
	end
	moho:SetSelLayer(originalLayer)
	moho:UpdateUI()
	moho:UpdateSelectedChannels()
in this test snippet was to temporarily make each of the layers I intend to scan the "current" layer. That way, I could go through the list and still be able to call up existing tools (the shape picker, I think in this case) that work on the current layer from within the scriptwithout modifying them, and just assign it back to the original layer at the end. I was scratching my head about that one when I checked out your code. So, thanks Myles.

Also, I just threw in the UpdateUI() on a hunch, and then discovered when I took it back out to see what happened, Moho crashed. Guess it was a good hunch. I'll have to throw in all that scanning through sublayers, but it helps the start. Wish there was an easier way. I'm sure I could whip something out using an external library, but I'd like to keep the cross-platform thing proper.

--Brian
User avatar
maxic
Posts: 64
Joined: Wed Sep 22, 2004 8:24 am
Location: Moscow, Russian Federation
Contact:

Post by maxic »

Thanks Myles, thanks Brian.
You have very much helped me.
Here that at me it has turned out
Post Reply