Hi everybody,
I have a rigged character that I've scripted to have seamless IKFK switching with forearm and upper-arm twists...
The script works great--from the script editor. And when I have the names of all my joints typed in properly. I want my character to be importable into other scenes, and for it to work right off the bat. Namespaces present a bit of a problem here. i have a lot of getAttr and setAttr commands in my code, and I want to have a mel script that updates to accomodate any altered names (without me having to re-type all my joint names in my code for it to get things right)
Expressions written in the expression editor (duh) work great with this, as they create an actual node that's connected to the objects they deal with. And if I change the names of those other nodes, the expression updates itself to accomodate. The problem is, Expressions don't utilize getAttr and setAttr commands (at least I don't think) and instead creates permanent connections to stream attribute values from one object to the next, as opposed to a one-time matching of values when I ask it to.
How would I create a script that I can use with my character, no matter what file she's in, and no matter what namespaces her joints are given? I'd be fine with a pop-up window asking me to click on a joint or something so it can determine the prefix to rename the joints or create a new script with the updated names, or whatever.
Here is the script:
if (getAttr IKFK:ArmControl.IKFK
== 1){
setAttr IKFK:ArmControl.IKFK 0;
//since we're going from FK to IK,//
// we first need to set the IK equal to the FK//
setAttr "IKFK:ikElbowPoleVector_world.translateX" getAttr IKFK:fkElbowLocator\_world.translateX
;
setAttr "IKFK:ikElbowPoleVector_world.translateY" getAttr IKFK:fkElbowLocator\_world.translateY
;
setAttr "IKFK:ikElbowPoleVector_world.translateZ" getAttr IKFK:fkElbowLocator\_world.translateZ
;
setAttr "IKFK:ikWristController_world.translateX" getAttr IKFK:fkWristLocator\_world.translateX
;
setAttr "IKFK:ikWristController_world.translateY" getAttr IKFK:fkWristLocator\_world.translateY
;
setAttr "IKFK:ikWristController_world.translateZ" getAttr IKFK:fkWristLocator\_world.translateZ
;
setAttr "IKFK:ikWristController_world.rotateX" getAttr IKFK:fkWristLocator\_world.rotateX
;
setAttr "IKFK:ikWristController_world.rotateY" getAttr IKFK:fkWristLocator\_world.rotateY
;
setAttr "IKFK:ikWristController_world.rotateZ" getAttr IKFK:fkWristLocator\_world.rotateZ
;
print "FK mode disengaged, captain. IK Initiated.";
} else {
setAttr IKFK:ArmControl.IKFK 1;
//since we're going from IK to FK, we first need//
//to set the FK equal TO the IK//
setAttr "IKFK:fkShoulderController.rotateX" getAttr IKFK:ikShoulder.rotateX
;
setAttr "IKFK:fkShoulderController.rotateY" getAttr IKFK:ikShoulder.rotateY
;
setAttr "IKFK:fkShoulderController.rotateZ" getAttr IKFK:ikShoulder.rotateZ
;
setAttr "IKFK:fkElbowController.rotateY" getAttr IKFK:ikElbow.rotateY
;
setAttr "IKFK:fkWristController.rotateX" getAttr IKFK:ikWrist.rotateX
;
setAttr "IKFK:fkWristController.rotateY" getAttr IKFK:ikWrist.rotateY
;
setAttr "IKFK:fkWristController.rotateZ" getAttr IKFK:ikWrist.rotateZ
;
print "FK mode ACTIVATED!!!";
};
//Now it's time to set the keyframes on your controls//
setKeyframe -attribute IKFK IKFK:ArmControl;
setKeyframe -attribute translate IKFK:ikElbowPoleVector_world;
setKeyframe -attribute translate IKFK:ikWristController_world;
setKeyframe -attribute rotate IKFK:ikWristController_world;
setKeyframe -attribute rotate IKFK:fkShoulderController;
setKeyframe -attribute rotate IKFK:fkElbowController;
setKeyframe -attribute rotate IKFK:fkWristController;
As you can see, I've already had to go in and adjust the namespaces for this script... I don't want to do this every time, much less those i give the rig to!
Any suggestions?