// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== global proc int connectToIKFK() // // Description: // Connects a node to an ikHandle so it can control IK/FK. // By default all joints in an IK chain are connected, this is // for other objects that someone may want to use to control IK/FK // switching. // // There should be at least two items in the selected array. The last // item should be a IK handle. // { string $selected[] = `ls -sl`; int $nSelected = size($selected); if ($nSelected < 2) { error((uiRes("m_connectToIKFK.kSelectTwo"))); } int $handleIndex = $nSelected-1; string $handle = $selected[$handleIndex]; if (!size(`ls -type "ikHandle" $handle`)) { int $foundHandle = 0; if ($nSelected == 2) { if (size(`ls -type "ikHandle" $selected[0]`)) { $handle = $selected[0]; $selected[0] = $selected[1]; $foundHandle = 1; } } if (! $foundHandle) { error((uiRes("m_connectToIKFK.kLastSelected"))); } } int $ii = 0; int $connected = 0; for ($ii = 0; $ii < $handleIndex; $ii++) { string $object = $selected[$ii]; string $attrName = ".ikBlend"; if (size(`ls ($object+".solverEnable")`)) { // In 5.0, the solverEnable attribute name was switched to // ikBlend. // if (`isConnected ($handle+".ikBlend") ($object+".solverEnable")`) { disconnectAttr ($handle+".ikBlend") ($object+".solverEnable"); } setAttr -k off ($object+".solverEnable"); } if (!size(`ls ($object+$attrName)`)) { addAttr -ln ikBlend -at double $object; setAttr -k on ($object+$attrName); } if (!`isConnected ($handle+".ikBlend") ($object+".ikBlend")`) { connectAttr ($handle+".ikBlend") ($object+".ikBlend"); $connected++; } else { string $format = (uiRes("m_connectToIKFK.kBlendAlreadyConnected")); string $warnMsg = `format -stringArg $object -stringArg $handle $format`; warning ($warnMsg); } } if ($connected > 0) { string $format = (uiRes("m_connectToIKFK.kConnectionsMade")); string $msg = `format -stringArg $connected $format`; print $msg; } else { print ((uiRes("m_connectToIKFK.kNoConn"))); } return $connected; }