Page 1 of 1

Keyframes in swithlayer

Posted: Thu Dec 16, 2004 12:17 am
by maxic
As in LUA to receive quantity keyframes in swithlayer and their values?

Posted: Thu Dec 16, 2004 1:22 am
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

Posted: Thu Dec 16, 2004 3:14 am
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

Posted: Fri Dec 17, 2004 12:00 am
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.

Posted: Fri Dec 17, 2004 4:43 am
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

Posted: Fri Dec 17, 2004 10:49 am
by maxic
Thanks Myles, thanks Brian.
You have very much helped me.
Here that at me it has turned out