Monday 5 May 2014

For anyone who needs it...

...but mainly for myself if I lose it... here's a bit of code to use to set up a basic FK/IK switch!
(this piece of code assumes you already created the 3 chains and the switch curve, and added an attribute to the switch to control switching) [if anyone would like some code to create the extra chains and the switch, just get in touch!]

This example is a hardcode from my own example, to use it you'd need to substitute in the names of your own joints, and lines can be duplicated/removed as necessary, depending on the limb you're working with. Good practice would be to use variables rather than hardcoding the names, but it you want to quickly throw a switch together without too much set-up, this'll do the job!


#set up constraints

cmds.orientConstraint('Rt_FK_Leg_0_JNT', 'Rt_Leg_0_JNT')

cmds.orientConstraint('Rt_IK_Leg_0_JNT', 'Lf_Leg_0_JNT')



#set up SDKs for ikfk switch

#Leg_0 FK
cmds.select('Lf_Leg_0_JNT_orientConstraint1')
cmds.setDrivenKeyframe(at='Lf_FK_Leg_0_JNTW0', cd='Lf_LegSwitch_0_CTL.FKIK', dv=0, v=1)
cmds.setDrivenKeyframe(at='Lf_FK_Leg_0_JNTW0', cd='Lf_LegSwitch_0_CTL.FKIK', dv=1, v=0)

#Leg_0 IK
cmds.select('Lf_Leg_0_JNT_orientConstraint1')
cmds.setDrivenKeyframe(at='Lf_IK_Leg_0_JNTW1', cd='Lf_LegSwitch_0_CTL.FKIK', dv=0, v=0)
cmds.setDrivenKeyframe(at='Lf_IK_Leg0_0_JNTW1', cd='Lf_LegSwitch_0_CTL.FKIK', dv=1, v=1)

No comments :

Post a Comment