Hello everyone, I have this script for matching IK and FK. I can get everything to match perfectly except the pole vector. Any ideas? I can get it to mostly match having a locator on the PV control parent constrained to the elbow joint, but it isn’t always perfect going between the two systems. It has a tendency for the locator to move when swapping to IK.
These are the scripts I’m using:
(expression 1)
//left arm
//FK
left_arm_shoulder_parentConstraint1.FK_left_arm_shoulderW1 = left_arm_IKFK_switch.Constraints;
left_arm_elbow_parentConstraint1.FK_left_arm_elbowW1 = left_arm_IKFK_switch.Constraints;
left_arm_forearm_orientConstraint1.FK_left_arm_wristW1 = left_arm_IKFK_switch.Constraints;
left_arm_wrist_parentConstraint1.FK_left_arm_wristW1 = left_arm_IKFK_switch.Constraints;
FK_left_arm_shoulder_control.visibility = left_arm_IKFK_switch.Constraints;
//IK
left_arm_shoulder_parentConstraint1.IK_left_arm_shoulderW0 = !left_arm_IKFK_switch.Constraints;
left_arm_elbow_parentConstraint1.IK_left_arm_elbowW0 = !left_arm_IKFK_switch.Constraints;
left_arm_forearm_orientConstraint1.IK_left_arm_wristW0 = !left_arm_IKFK_switch.Constraints;
left_arm_wrist_parentConstraint1.IK_left_arm_wristW0 = !left_arm_IKFK_switch.Constraints;
left_IK_hand_control.visibility = !left_arm_IKFK_switch.Constraints;
left_arm_PV_control.visibility = !left_arm_IKFK_switch.Constraints;
expression 2:
scriptJob -attributeChange “left_arm_IKFK_switch.IKFK” “IKFKMatch()”;
script node:
global proc IKFKMatch()
{
//left arm
int $switchCheck = getAttr left_arm_IKFK_switch.IKFK
;
print("switch is at " + $switchCheck);
if ($switchCheck == 0)
{
float $laikXrot = `getAttr left_arm_hand_IK_match_locator.rotateX`;
float $laikYrot = `getAttr left_arm_hand_IK_match_locator.rotateY`;
float $laikZrot = `getAttr left_arm_hand_IK_match_locator.rotateZ`;
float $laikXtrans = `getAttr left_arm_hand_IK_match_locator.translateX`;
float $laikYtrans = `getAttr left_arm_hand_IK_match_locator.translateY`;
float $laikZtrans = `getAttr left_arm_hand_IK_match_locator.translateZ`;
setAttr left_IK_hand_control.rotateX $laikXrot;
setAttr left_IK_hand_control.rotateY $laikYrot;
setAttr left_IK_hand_control.rotateZ $laikZrot;
setAttr left_IK_hand_control.translateX $laikXtrans;
setAttr left_IK_hand_control.translateY $laikYtrans;
setAttr left_IK_hand_control.translateZ $laikZtrans;
float $lapvmatchX = `getAttr left_arm_pv_match_locator.translateX`;
float $lapvmatchY = `getAttr left_arm_pv_match_locator.translateY`;
float $lapvmatchZ = `getAttr left_arm_pv_match_locator.translateZ`;
setAttr left_arm_PV_control.translateX $lapvmatchX;
setAttr left_arm_PV_control.translateY $lapvmatchY;
setAttr left_arm_PV_control.translateZ $lapvmatchZ;
setAttr left_arm_IKFK_switch.constraints 0;
}
if ($switchCheck == 1)
{
float $lashXrot = `getAttr left_arm_shoulder_FK_match_locator.rotateX`;
float $lashYrot = `getAttr left_arm_shoulder_FK_match_locator.rotateY`;
float $lashZrot = `getAttr left_arm_shoulder_FK_match_locator.rotateZ`;
setAttr FK_left_arm_shoulder_control.rotateX $lashXrot;
setAttr FK_left_arm_shoulder_control.rotateY $lashYrot;
setAttr FK_left_arm_shoulder_control.rotateZ $lashZrot;
float $laelXrot = `getAttr left_arm_elbow_FK_match_locator.rotateX`;
float $laelYrot = `getAttr left_arm_elbow_FK_match_locator.rotateY`;
float $laelZrot = `getAttr left_arm_elbow_FK_match_locator.rotateZ`;
setAttr FK_left_arm_elbow_control.rotateX $laelXrot;
setAttr FK_left_arm_elbow_control.rotateY $laelYrot;
setAttr FK_left_arm_elbow_control.rotateZ $laelZrot;
float $lawrXrot = `getAttr left_arm_wrist_FK_match_locator.rotateX`;
float $lawrYrot = `getAttr left_arm_wrist_FK_match_locator.rotateY`;
float $lawrZrot = `getAttr left_arm_wrist_FK_match_locator.rotateZ`;
setAttr FK_left_arm_wrist_control.rotateX $lawrXrot;
setAttr FK_left_arm_wrist_control.rotateY $lawrYrot;
setAttr FK_left_arm_wrist_control.rotateZ $lawrZrot;
setAttr left_arm_IKFK_switch.constraints 1;
}
}