Copying/moving keyframes within the same layer channel?

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

Moderators: Víctor Paredes, Belgarath, slowtiger

lehtiniemi
Posts: 107
Joined: Mon Jan 14, 2013 3:18 pm

Copying/moving keyframes within the same layer channel?

Post by lehtiniemi »

I thought I'd write a tool to easily cut and insert "time" so that you could drag the tool and add/remove the corresponding amount of frames.

This means moving around keyframes. Is there a way to do this easily? The current scripting interface doesn't provide a way to read the interpolation type (at least I couldn't find it in the reference) so you can't duplicate a frame and be sure about the interpolation type by reading and re-adding a frame. Or is there a function to copy keyframes directly?

What I'm trying to do is to cut/add X amount of frames on every layer in the document so my plan is just move them backwards/forwards X frames. The only functionality that's built-in I've found to do this is "Rescale animation". I'd just write a handier tool for this. If there's already a tool for this, I'm happy to hear about it! :)
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Copying/moving keyframes within the same layer channel?

Post by synthsin75 »

Get key interpolation:

Code: Select all

	local Interp = 0
	local ch = moho.layer.fTranslation
	ch:GetKeyInterp(moho.frame, Interp)
lehtiniemi
Posts: 107
Joined: Mon Jan 14, 2013 3:18 pm

Re: Copying/moving keyframes within the same layer channel?

Post by lehtiniemi »

Ooh thanks! The animestudioscripting.com didn't have this, but then again, it says there it's for version 10. (or if it did, then I missed this) Thanks again!
synthsin75 wrote:Get key interpolation:

Code: Select all

	local Interp = 0
	local ch = moho.layer.fTranslation
	ch:GetKeyInterp(moho.frame, Interp)
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Copying/moving keyframes within the same layer channel?

Post by synthsin75 »

http://aslua.com/ is a better reference...aside from the scripting files included with AS (but even those occasionally end up out-of-date).
lehtiniemi
Posts: 107
Joined: Mon Jan 14, 2013 3:18 pm

Re: Copying/moving keyframes within the same layer channel?

Post by lehtiniemi »

I'm trying to shift all the animation in the whole document and trying to find a good way to do this.

Some issues:

Looping through all layers:
-moho.document has CountLayers and Layer-function that gives me all the TOP-LEVEL layers. How do I access group layers and layers contained by bone layers? You can access layer's parent from a sub-layer, but how do I access the sub-layers from the parent-layer?

Moving keyframes:
-MohoLayer has "CopyFrame", but this seems to add keyframes even if there's no animation, so it's no use.
-Is there a way to access ALL the AnimChannels when I have the layer, so I could just loop through them? Then it would be easy to just check which ones have keyframes and duplicate them. AnimChannel even has a SwapKeys-function that would assumably make moving whole keyframes around easier.
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Copying/moving keyframes within the same layer channel?

Post by hayasidist »

looping though all layers:

a group type layer has a count of child layers - see: http://aslua.com/index.php?show=method& ... ers&id=637 a recursive loop through that will pick out every layer in a doc.

finding and copying keyframes:

a layer has a count of the channels: see http://aslua.com/index.php?show=method& ... els&id=551 - beware: the last channel is "all" so the loop is for 1 = 0, moho.layer:CountChannels()-2 Also, document-wide channels such as camera stuff is likely to show in every layer.

a channel has a count of subchannels: see http://aslua.com/index.php?show=class&n ... yerChannel if that's more than 1 you'll need to scan sublayers

a (sub)channel will always have one key (at frame zero) so you'll want to pick out the ones with 2 or more keys.
a (sub)channel has a duration: see http://aslua.com/index.php?show=method& ... ion&id=418 ; and we've previously talked about a search for keys - if you're planning on adding space a "start at the back and move things further backwards" strategy is probably best

also take a look in the release directory ".../scripts/script writing" folder for (something like) lm_Listchannels.lua

hope that helps!
lehtiniemi
Posts: 107
Joined: Mon Jan 14, 2013 3:18 pm

Re: Copying/moving keyframes within the same layer channel?

Post by lehtiniemi »

Wow, thanks for a through answer!!! I'll dig into this. :)
lehtiniemi
Posts: 107
Joined: Mon Jan 14, 2013 3:18 pm

Re: Copying/moving keyframes within the same layer channel?

Post by lehtiniemi »

Just one quick clarification from the top of my head: what are subchannels? Is it like if there's channel "Perspective shadow", then subchannel would be "shadow scale", "shadow sheer" etc?
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Copying/moving keyframes within the same layer channel?

Post by synthsin75 »

Yeah, any channel that has extra settings associated with its keyframes.
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Copying/moving keyframes within the same layer channel?

Post by hayasidist »

must say I've never bothered to look before you asked about layer perspective shadow! But .... if, e.g., the channel is point motion then the sub channels are one per point.

However, IMO it's mostly irrelevant exactly what the channels / sub channels are if all you're doing is copying. I'm not even sure you need to worry about channel type (e.g. scalar, vector, string ...).
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Copying/moving keyframes within the same layer channel?

Post by synthsin75 »

You can see all the channels and their subchannels by running Scripts>Script Writing>List Channels.

Point motion has no subchannels. Selected point motion is its own channel.


But yeah, shouldn't be much need to delve into subchannels just to move keyframes.
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Copying/moving keyframes within the same layer channel?

Post by synthsin75 »

Uh, I haven't used them, but shouldn't these be all you need?

void CopyFrame(int32 fromFrame, int32 toFrame, bool recursive);
void DeleteFrame(int32 frame, bool recursive);


EDIT: Oh right, it keys all channels and doesn't preserve interpolation.
lehtiniemi
Posts: 107
Joined: Mon Jan 14, 2013 3:18 pm

Re: Copying/moving keyframes within the same layer channel?

Post by lehtiniemi »

synthsin75 wrote:Uh, I haven't used them, but shouldn't these be all you need?

void CopyFrame(int32 fromFrame, int32 toFrame, bool recursive);
void DeleteFrame(int32 frame, bool recursive);


EDIT: Oh right, it keys all channels and doesn't preserve interpolation.
Yea I was really excited when I found those but it's as shake they don't have some argument like "only copy keyframes" like some other functions. But with a little recursivity and a couple of haskey-checks, moving around keyframes will ever a breeze! I'll post here my finished subroutines when I get to it. Thanks for help!!!
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Copying/moving keyframes within the same layer channel?

Post by hayasidist »

synthsin75 wrote:You can see all the channels and their subchannels by running Scripts>Script Writing>List Channels.
Point motion has no subchannels. Selected point motion is its own channel.
sorry to disagree Wes- but point motion does have subchannels (and selected point motion has subchannels if more than one point is selected)
(screenshot here if you want to take a look: http://i128.photobucket.com/albums/p196 ... malgap.png)


and, whilst I haven't used it -- AnimChannel:SetKeyWhen(id, when) just might allow an existing id to be relocated?
lehtiniemi
Posts: 107
Joined: Mon Jan 14, 2013 3:18 pm

Re: Copying/moving keyframes within the same layer channel?

Post by lehtiniemi »

hayasidist wrote:
synthsin75 wrote:You can see all the channels and their subchannels by running Scripts>Script Writing>List Channels.
Point motion has no subchannels. Selected point motion is its own channel.
sorry to disagree Wes- but point motion does have subchannels (and selected point motion has subchannels if more than one point is selected)
(screenshot here if you want to take a look: http://i128.photobucket.com/albums/p196 ... malgap.png)


and, whilst I haven't used it -- AnimChannel:SetKeyWhen(id, when) just might allow an existing id to be relocated?

Ooh, info worth gold! This would be so cool, to have the ability to move them instead of having to copy them.
Post Reply