Smarter "Copy Current frame..."

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

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
Víctor Paredes
Site Admin
Posts: 5646
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Smarter "Copy Current frame..."

Post by Víctor Paredes »

Hi. Do you know if there's a script that works in a similar way to the "Copy current frame..." option in the Animation menu?
I need to copy a frame of a very complex character into another frame.
The menu feature works if I check the "Copy entire animation" option, but it's far to be ideal, since it adds keyframes for all the channels of all the layers. And that is a lot of channels in a lot of layers...
What I'm looking for is a script that would only create keyframes for channels that already have animation and ignore the rest.

Do you know if any script with a similar behavior?

Thank you very much.
Image Image Image Image
Moho Product Manager

www.mohoanimation.com
Rigged animation supervisor in My father's dragon - Lead Moho artist in Wolfwalkers - Cartoon Saloon - My personal Youtube Channel
Stan
Posts: 199
Joined: Sun Apr 19, 2009 3:22 pm

Re: Smarter "Copy Current frame..."

Post by Stan »

So, as I see it, a menu/button script that will open a dialog with just "From frame: __ to frame __", and by clicking OK will copy all animated channels for the selected layer(s) only, including all sub-layers, right?

I could try to make it, just not sure if I have enough time this upcoming weekend...
________________________________________________________________________
https://mohoscripting.com/ - Unofficial Moho Lua scripting documentation
https://mohoscripts.com/ - The best place to publish and download scripts for Moho
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Smarter "Copy Current frame..."

Post by hayasidist »

Since I've been working on channels recently I've got quite a few bits of code hanging around --- here's a snippet as a starter ... Only for Moho 12 or later

It gets the "all channels" channel for a layer and for every subchannel that is of non-zero duration sets a key at the target.

Code: Select all

	for j = 0, ctChannels-1 do 
		local chInfo = MOHO.MohoLayerChannel:new_local()
		moho.layer:GetChannelInfo(j, chInfo)
		local ch
		local subChans = chInfo.subChannelCount
		if chInfo.channelID == CHANNEL_LAYER_ALL then
				for k = 0, subChans - 1 do
					ch = moho.layer:Channel(j, k, moho.document) 
					local chDet
					if ch:Duration() > 0 then 
						if ch:ChannelType() == MOHO.CHANNEL_BOOL then
							chDet = moho:ChannelAsAnimBool(ch)
						elseif ch:ChannelType() == MOHO.CHANNEL_COLOR then
							chDet = moho:ChannelAsAnimColor(ch)
						elseif ch:ChannelType() == MOHO.CHANNEL_STRING then
							chDet = moho:ChannelAsAnimString(ch)
						elseif ch:ChannelType() == MOHO.CHANNEL_VAL then
							chDet = moho:ChannelAsAnimVal(ch)
						elseif ch:ChannelType() == MOHO.CHANNEL_VEC2 then
							chDet = moho:ChannelAsAnimVec2(ch)
						elseif ch:ChannelType() == MOHO.CHANNEL_VEC3 then
							chDet = moho:ChannelAsAnimVec3(ch)
						end
						local val = ch.value -- value at current frame (or use chDet:GetValue(inframe) )
						chDet:SetValue(outframe, val)
					end
				end
			end
		end
so you'll need to iterate over all layers (e.g. http://www.mohoscripting.com/index.php? ... ippet&id=1 ) and whatever UI you fancy..
User avatar
Víctor Paredes
Site Admin
Posts: 5646
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Re: Smarter "Copy Current frame..."

Post by Víctor Paredes »

Stan wrote:So, as I see it, a menu/button script that will open a dialog with just "From frame: __ to frame __", and by clicking OK will copy all animated channels for the selected layer(s) only, including all sub-layers, right?
I could try to make it, just not sure if I have enough time this upcoming weekend...
Yes, it's exactly that. Thank you very much for your message and I'm sorry i didn't answer you before.
Don't worry about writing the scripts (but huge thanks for the offer), we will see what can be done here.
It was I wasn't sure something similar was done in the past.
hayasidist wrote:Since I've been working on channels recently I've got quite a few bits of code hanging around --- here's a snippet as a starter ... Only for Moho 12 or later
This is great. Thank you very much for the help! We will explore the idea.
Image Image Image Image
Moho Product Manager

www.mohoanimation.com
Rigged animation supervisor in My father's dragon - Lead Moho artist in Wolfwalkers - Cartoon Saloon - My personal Youtube Channel
Stan
Posts: 199
Joined: Sun Apr 19, 2009 3:22 pm

Re: Smarter "Copy Current frame..."

Post by Stan »

Victor, if you just need the speed, there is a quick method MohoLayer:CopyFrame(fromFrame, toFrame, recursive). It copies every single channel, but does it very fast and easy.
________________________________________________________________________
https://mohoscripting.com/ - Unofficial Moho Lua scripting documentation
https://mohoscripts.com/ - The best place to publish and download scripts for Moho
User avatar
A.Evseeva
Posts: 61
Joined: Wed Apr 08, 2015 8:43 am
Contact:

Re: Smarter "Copy Current frame..."

Post by A.Evseeva »

Here is the tool that Stan mentioned above. It is our first collaboration.
http://revival.ru/test/ae_keytools.zip
To copy channel values go to source frame, press the COPY button, then go to target frame and press PASTE.
Keys will be created in animated channels only and in all the sub-layers if the "Child Layers" checkbox is checked.
It also can add new keyframes with ADD button using strange but useful logic (it is mainly for those animators who did not add keyframes before animating and found their previous animation destructed by new keyframes added later)
User avatar
Víctor Paredes
Site Admin
Posts: 5646
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Re: Smarter "Copy Current frame..."

Post by Víctor Paredes »

A.Evseeva wrote:Here is the tool that Stan mentioned above. It is our first collaboration.
http://revival.ru/test/ae_keytools.zip
Thank you very much A.Evseeva!
I'm sorry I couldn't reply before. The script seems to be working perfectly and it's exactly what we needed.
Thank you very much again for your generosity.
Image Image Image Image
Moho Product Manager

www.mohoanimation.com
Rigged animation supervisor in My father's dragon - Lead Moho artist in Wolfwalkers - Cartoon Saloon - My personal Youtube Channel
User avatar
Greenlaw
Posts: 9192
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: Smarter "Copy Current frame..."

Post by Greenlaw »

Good info in this thread!

I actually needed something like this last night. Will give some of these suggestions a try soon.
User avatar
Víctor Paredes
Site Admin
Posts: 5646
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Re: Smarter "Copy Current frame..."

Post by Víctor Paredes »

Hi, I just came to say I'm using this script a lot. Thanks again!
Image Image Image Image
Moho Product Manager

www.mohoanimation.com
Rigged animation supervisor in My father's dragon - Lead Moho artist in Wolfwalkers - Cartoon Saloon - My personal Youtube Channel
User avatar
Víctor Paredes
Site Admin
Posts: 5646
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Re: Smarter "Copy Current frame..."

Post by Víctor Paredes »

Hi, I was wondering if there's a chance the copy/paste option of this script could work between different opened files.
Many times I need to use a pose of exactly the same character, but from a different file.
Do you know if that would be possible?

Thank you very much. And, again, this is script is fantastic. Currently I'm using it in every single scene I animate :)
Image Image Image Image
Moho Product Manager

www.mohoanimation.com
Rigged animation supervisor in My father's dragon - Lead Moho artist in Wolfwalkers - Cartoon Saloon - My personal Youtube Channel
User avatar
A.Evseeva
Posts: 61
Joined: Wed Apr 08, 2015 8:43 am
Contact:

Re: Smarter "Copy Current frame..."

Post by A.Evseeva »

It already can do this for selected layer. I will try to add this feature for sublayers. Possible problem is assigning sublayers one to another if layer order was changed.
User avatar
A.Evseeva
Posts: 61
Joined: Wed Apr 08, 2015 8:43 am
Contact:

Re: Smarter "Copy Current frame..."

Post by A.Evseeva »

Uploaded a new version which can copy-paste between open files including sublayers.
http://revival.ru/public_soft/lua/ae_keytools.zip
User avatar
Lukas
Posts: 1295
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Smarter "Copy Current frame..."

Post by Lukas »

A.Evseeva wrote:Uploaded a new version which can copy-paste between open files including sublayers.
http://revival.ru/public_soft/lua/ae_keytools.zip
Brilliant! Thanks for sharing.
User avatar
Víctor Paredes
Site Admin
Posts: 5646
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Re: Smarter "Copy Current frame..."

Post by Víctor Paredes »

A.Evseeva wrote:Uploaded a new version which can copy-paste between open files including sublayers.
http://revival.ru/public_soft/lua/ae_keytools.zip
Thank you very much! I'm having some issues testing it in this project (but it's probably because these characters are very complex). I will try again when I get some time :)
Image Image Image Image
Moho Product Manager

www.mohoanimation.com
Rigged animation supervisor in My father's dragon - Lead Moho artist in Wolfwalkers - Cartoon Saloon - My personal Youtube Channel
User avatar
A.Evseeva
Posts: 61
Joined: Wed Apr 08, 2015 8:43 am
Contact:

Re: Smarter "Copy Current frame..."

Post by A.Evseeva »

Released a new version: http://revival.ru/public_soft/lua/moho_ ... l=keytools
new features:
- an option to select all the keys on all layers
- an option to exclude reference layers from this and other operations
- button to copy and paste key options (such as easy handles) from one key to another
Post Reply