Notifications
Clear all

[Closed] Using a CA checkbox to toggle ik / fk?

Hi Folks,

I’m doing some rigging at the minute and I’ve got a scripted setup that makes a skinning bone chain through a set of 5 points, makes an IK arm setup from point helpers based on the bone positions and a third FK arm setup using some spline objects that act as rotators. I’ve got a spline helper attached to the hand bone in the chain with an attribute holder modifier and a checkbox, and what I’d like to do is use the checkbox to switch what setup the skinning bones are weighted towards. I’d be able to do the lot using a spinner / slider and parameter wiring on the orientation constraints but I’d love to have the toggle button instead so I can use it as an event to hide / unhide the relevant set of arm controls for the sake of a clean interface for the animator. Oddly enough what I’m struggling with is actually where to put the expression and what handler / Event I’d use to actually do the switch?

So for the modifier I’ve got something really simple:


the_IkFkSwitch = attributes IkSwitch
(
	parameters main rollout:params
	(
		IkFkState type:#boolean ui:IkFkToggle default:false
	)

	rollout params "Ik / Fk Toggle"
	(
		checkbox IkFkToggle "IK On:" Checked:false
	)
)

custAttributes.add $ the_IkFkSwitch

And $.baseObject.IkSwitch.IkFkState = off / on seems to toggle it fine but what I’m wondering is what kind of handler I’d have to use to set off a script or change other objects when this toggle occurs?

In plain english the following will happen on toggle:

If you’re in IK mode the FK controls have a key saved on the previous frame so their animation won’t change, they have a key saved at the current frame, and their transforms are matched to the IK bones. The IK controls get hidden and the Skinning bones become 100% constrained to the FK bones.

If you’re in FK the reverse, the IK helpers have a key saved, the goal object and plane solver are matched to the FK bones and then their controls get hidden and the Skin bones switch their constraint to the IK bones.

I’m presuming that the expression or script would sit on my ik / fk toggle objects but what would the event be and on what controller would I put it on?

Cheers for any thoughts!

John

5 Replies

Seems normal event handlers don’t work when assigned to the custom attribs?

Like for the above using ” on ikFkToggle changed state do print “hello” ” doesn’t output to the listener?

Where were you putting your event handler?

the_IkFkSwitch = attributes IkSwitch
(
	parameters main rollout:params
	(
		IkFkState type:#boolean ui:IkFkToggle default:false
	)

	rollout params "Ik / Fk Toggle"
	(
		checkbox IkFkToggle "IK On:" Checked:false
		
		on IkFkToggle changed state do
		(
			print state
		)
	)
)

custAttributes.add $ the_IkFkSwitch

The above works for me.

You’re bang on – I had the event handler outside the rollout so it wasn’t getting taken into account – much appreciated for the fix. For this type of thing I thought I’d have to look into callbacks using some kind of on changed method – hopefully this’ll work nicely though!

My stupid code with your correectly places handler:



the_IkFkSwitch = attributes IkSwitch
(
	parameters main rollout:params
	(
		IkFkState type:#boolean ui:IkFkToggle
	)

	rollout params "Ik / Fk Toggle"
	(
		-- checkbox IkFkToggle "IK On:" Checked:false
				
		radiobuttons IkFkToggle labels:#("IK", "FK")
		
		on IkFkToggle changed state do
		(
			print "hello"
		)	
		
	)
	


)

custAttributes.add $ the_IkFkSwitch


Glad you got that sorted but looking at your code I’ve spotted another problem. If you going to swap your checkbox for radio buttons then you will have to change IkFkState from type:#boolean to type:#integer and state will be an integer as well.

Yep, found the same thing – much appreciated!