Help: Color bone keys in the same colors as the bones?

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

Moderators: Fahim, Distinct Sun, Víctor Paredes, erey, Belgarath, slowtiger

Post Reply
User avatar
Lukas
Posts: 782
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Help: Color bone keys in the same colors as the bones?

Post by Lukas » Wed Nov 07, 2018 5:05 pm

Hi everyone,

I'm looking for a way to colorize all bone keyframes in the same color as the bone label of the actual bone the key belongs to.

Either via a script that looks at all keyframes in a bone layer and colors them correctly, or by putting some code after 'moho:NewKeyframe(CHANNEL_BONE_T)' etc, that colors the keys while your making them. (Or even better, both)

I don't really know where to start so any help would be greatly appreciated. :D
User avatar
synthsin75
Posts: 7081
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Help: Color bone keys in the same colors as the bones?

Post by synthsin75 » Wed Nov 07, 2018 5:28 pm

I guess the separate bone color channels don't do what you want?
- Wes
ImageImageImage
User avatar
Lukas
Posts: 782
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Help: Color bone keys in the same colors as the bones?

Post by Lukas » Thu Nov 08, 2018 11:56 am

They do, but more often than not they are hidden to avoid timeline clutter. In some situations seeing the keys by color could really help the animators.
User avatar
chucky
Posts: 3908
Joined: Sun Jan 28, 2007 4:24 am
Location: Van Diemen's Land
Contact:

Re: Help: Color bone keys in the same colors as the bones?

Post by chucky » Sat Nov 10, 2018 5:50 am

Sounds like a cool idea.
Sometimes I use this method which helps with stuff like blinks which can clutter timelines.
It only works with stuff like this because it starts with an action.
Colour the keys in the action for ' blink'
then the blink action, when dropped into the mainline, carries the key colours. Then I know which keys are the blink bones.

The thing I really want to reduce timeline clutter is to stop translate and scale keys being laid for smart bone dials and bones that only rotate. Some targets only need translate keys.
This would mean the bone select tool could designate which channels to key.
Sequential offender.
my latest animations
User avatar
Lukas
Posts: 782
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Help: Color bone keys in the same colors as the bones?

Post by Lukas » Mon Nov 12, 2018 8:40 am

chucky wrote:The thing I really want to reduce timeline clutter is to stop translate and scale keys being laid for smart bone dials and bones that only rotate. Some targets only need translate keys.
This would mean the bone select tool could designate which channels to key.
Totally agree!

I’ve actually built a tool that does just that, but it’s really tailored to our workflow/pipeline and still has some quirks/bugs/crashes. It also has a button that removes those unwanted keyframes in a project animated with the regular tools.

Regular bones (not pin-bones) with labels AND constraints are considered smartbonedials, and are only able to get rotation keys, they are impossible to translate or scale with the tool.
If a pinbone has a label it is considered a smartbonetarget, and is only translatable.
A cool bonus thing is, if you do try to translate a smartbonedial, it actually translates the hidden "GUI" bone (which all dials are parented to in our rigs), but puts the translation key at frame 1, that way dials never float all over your scene.

We're already using the tool for all bone animation in production, but it's still a work in progress and not ready for a public release. I'll see if I can release only this part of the code, because this part is not causing any crashes.

Edit: Here's a menu script that deletes those keys: http://www.lukaskrepel.nl/temp/ASP/lk_r ... n_keys.lua

...But, hopefully the official team tackles this problem with better bone constraints.
User avatar
Lukas
Posts: 782
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Help: Color bone keys in the same colors as the bones?

Post by Lukas » Thu Nov 15, 2018 5:08 pm

I guess it's not possible. I'd need something like:

Code: Select all

AnimChannel:SetLabelColor(when, colID)
or

Code: Select all

AnimChannel:SetLabelColorByID(keyID, colID)
But no command like it seems to exist. :(

(Right?) :|
User avatar
synthsin75
Posts: 7081
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Help: Color bone keys in the same colors as the bones?

Post by synthsin75 » Thu Nov 15, 2018 7:48 pm

Lukas wrote:I guess it's not possible. I'd need something like:

Code: Select all

AnimChannel:SetLabelColor(when, colID)
or

Code: Select all

AnimChannel:SetLabelColorByID(keyID, colID)
But no command like it seems to exist. :(

(Right?) :|

Code: Select all

	--get key color
	local interp = MOHO.InterpSetting:new_local()
	local ch = moho.layer.fTranslation
	ch:GetKeyInterp(moho.frame, interp)
	local tags = {"Plain", "Red", "Orange", "Yellow", "Green", "Blue", "Purple", "Tan", "Pink", "Torquoise", "Cadet Blue", "Coral"}
	print(tags[interp.tags+1])
	--set key color
	interp.tags = 0 --Plain
	ch:SetKeyInterp(moho.frame, interp)
The color number codes are the same as those for bones: http://mohoscripting.com/methods/999
I just made the "tags" table to print the color names.
- Wes
ImageImageImage
User avatar
Lukas
Posts: 782
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Help: Color bone keys in the same colors as the bones?

Post by Lukas » Thu Nov 15, 2018 8:24 pm

synthsin75 wrote:

Code: Select all

	--get key color
	local interp = MOHO.InterpSetting:new_local()
	local ch = moho.layer.fTranslation
	ch:GetKeyInterp(moho.frame, interp)
	local tags = {"Plain", "Red", "Orange", "Yellow", "Green", "Blue", "Purple", "Tan", "Pink", "Torquoise", "Cadet Blue", "Coral"}
	print(tags[interp.tags+1])
	--set key color
	interp.tags = 0 --Plain
	ch:SetKeyInterp(moho.frame, interp)
D'oh. I didn't realise the color labels where accessible trough the interpolation settings for keys, this is great. Thanks a lot, again, Wes!
User avatar
synthsin75
Posts: 7081
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Help: Color bone keys in the same colors as the bones?

Post by synthsin75 » Fri Nov 16, 2018 3:27 am

Lukas wrote:D'oh. I didn't realise the color labels where accessible trough the interpolation settings for keys, this is great. Thanks a lot, again, Wes!
Glad to help, Lukas. I was meaning to get around to writing this script, but I haven't found the time.
- Wes
ImageImageImage
User avatar
Lukas
Posts: 782
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Help: Color bone keys in the same colors as the bones?

Post by Lukas » Fri Nov 16, 2018 10:44 am

Ok, so here's a script you can run on a bone layer and it will color all bone keys according to the bone colors:
http://www.lukaskrepel.nl/temp/ASP/LK_PaintKeys.lua

You could use it as a menu script, and edit in this line in all 'onmouseup' functions (at the end of the function, before the last end) of the transform bone tool and manipulate bone tool (or whatever you're using to animate bones) and it will color keys while your setting them. (It would color all keys all the time, but it doesn't seem to slow things down at all):

Code: Select all

LK_PaintKeys:Run(moho)
Here's the whole thing:

Code: Select all

ScriptName = "LK_PaintKeys"

LK_PaintKeys = {}

function LK_PaintKeys:Name()
	return "Paint keys"
end

function LK_PaintKeys:Version()
	return "0.01"
end

function LK_PaintKeys:IsBeginnerScript()
	return false
end

function LK_PaintKeys:Description()
	return ("Paint keys the same color as their corresponding bones")
end

function LK_PaintKeys:Creator()
	return "Lukas Krepel, Frame Order"
end

function LK_PaintKeys:UILabel()
	return ("Paint bone keyframes")
end

function LK_PaintKeys:IsEnabled(moho)
	if moho.layer:IsBoneType() and moho:CountBones() > 0 then
		return true
	end
	return false
end

function LK_PaintKeys:IsRelevant(moho)
	if moho.layer:IsBoneType() then
		return true
	end
	return false
end

function LK_PaintKeys:Run(moho)
	local c, i
	local doc = moho.document
	local layer = moho.layer
	if layer:IsBoneType() then
		local boneLayer = moho:LayerAsBone(layer)
		local skel = boneLayer:Skeleton()
		if skel:CountBones() > 0 then
			local channels = {}
			for i = 0, skel:CountBones() - 1 do
				bone = skel:Bone(i)
				boneColor = bone:Tags()
				c = 0
				c = c + 1; channels[c] = skel:Bone(i).fAnimPos
				c = c + 1; channels[c] = skel:Bone(i).fAnimAngle
				c = c + 1; channels[c] = skel:Bone(i).fAnimScale
				c = c + 1; channels[c] = skel:Bone(i).fAnimParent
				c = c + 1; channels[c] = skel:Bone(i).fTargetBone
				c = c + 1; channels[c] = skel:Bone(i).fFlipH
				c = c + 1; channels[c] = skel:Bone(i).fFlipV
				c = c + 1; channels[c] = skel:Bone(i).fIKGlobalAngle
				c = c + 1; channels[c] = skel:Bone(i).fIKLock
				c = c + 1; channels[c] = skel:Bone(i).fIKParentTarget
				c = c + 1; channels[c] = skel:Bone(i).fPhysicsMotorSpeed
				for c = 1, #channels do
					channel = channels[c]
					local endKey = channel:Duration()
					local thisKey = 0
					local keyCount = channel:CountKeys()
					local keysFound = 0
					local frameNum = endKey
					while keysFound < keyCount do
						thisKey = channel:GetClosestKeyID(frameNum)
						keyFrameNum = channel:GetKeyWhen(thisKey)
						keysFound = 1 + keysFound
					   	local interp = MOHO.InterpSetting:new_local()
					    channel:GetKeyInterp(keyFrameNum, interp)
			   		    interp.tags = boneColor
			 		    channel:SetKeyInterp(keyFrameNum, interp)
						frameNum = keyFrameNum - 1
					end
				end
			end
		end
	end
end
Post Reply