// =========================================================================== // 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 ikFKSolverState(string $selectionList[]) // // Description: // Returns an int describing the solver enable state of the // selected joint chains or ikHandles. // // There are five different returned values: // 0 : No joints or ikHandles are selected. // 1 : The selected items have their solver enabled. // 2 : The selected items have their solver disabled. // 3 : No solver on the selcted joints. // 4 : Some of the selected items have their solvers // enabled and others have their solvers disabled. // { int $kNothingSelected = 0; int $kSolverEnabled = 1; int $kSolverDisabled = 2; int $kNoSolver = 3; int $kMixed = 4; int $nOtherHandles = 0; string $otherHandles[]; int $nOtherJoints = 0; string $otherJoints[]; string $xforms[] = `ls -type transform $selectionList`; int $nXforms = size($xforms); if ($nXforms == 0) { return $kNothingSelected; } string $ikRelated[] = `ls -type joint -type ikHandle $selectionList`; int $nIKRelated = size($ikRelated); string $item; if ($nIKRelated != $nXforms) { for ($item in $xforms) { string $attrName; if (size(`ls ($item+".solverEnable")`)) { $attrName = ($item+".solverEnable"); } else if (size(`ls ($item+".ikBlend")`)) { $attrName = ($item+".ikBlend"); } if (size($attrName)) { string $cnx[] = `listConnections -d 0 $attrName`; if (size($cnx) > 0 && !size(`ls -type joint $cnx[0]`)) { if (size(`ls -type ikHandle $cnx[0]`) > 0) { $otherHandles[$nOtherHandles++] = $cnx[0]; } else if (size(`ls -type joint $cnx[0]`) > 0) { $otherJoints[$nOtherHandles++] = $cnx[0]; } } } } } if ($nIKRelated == 0 && $nOtherHandles == 0 && $nOtherJoints == 0) { return $kNothingSelected; } int $ikOn = false; int $hasResult = false; int $mixed = false; string $selectedHandles[] = `ls -type "ikHandle" $ikRelated`; int $nHandles = size($selectedHandles); // Add the other handles that may be involved. // for ($item in $otherHandles) { $selectedHandles[$nHandles++] = $item; } for ($item in $selectedHandles) { int $enabled = (`getAttr ($item+".ikBlend")` > 0); if (!$hasResult) { $ikOn = $enabled; $hasResult = true; } else { if ($enabled != $ikOn) { $mixed = true; break; } } } if (!$mixed) { // Only look at the joints if it is necessary. // string $handles[] = `ls -type ikHandle`; string $jointList[] = `ls -type "joint" $ikRelated`; int $jointIndex = size($jointList); for ($item in $otherJoints) { $jointList[$jointIndex++] = $item; } string $selected; for ($selected in $jointList) { string $h; for ($h in $handles) { string $joints[] = `ikHandle -q -jl $h`; int $nJoints = size($joints); $joints[$nJoints] = `ikHandle -q -sj $h`; string $j; for ($j in $joints) { if (size(`match $selected $j`) > 0 && size(`match ($selected+"|") $j`) == 0) { string $attrName = ($h+".ikBlend"); if (size(`ls ($h+".solverEnable")`)) { $attrName = ($h+".solverEnable"); } int $enabled = (`getAttr $attrName` > 0); if (!$hasResult) { $ikOn = $enabled; $hasResult = true; } else { if ($enabled != $ikOn) { $mixed = true; break; } } } } if ($mixed) { break; } } if ($mixed) { break; } } } int $result; if (!$hasResult) { // There was no solver for the selected joints. // $result = $kNoSolver; } else { if ($mixed) { $result = $kMixed; } else { $result = $ikOn ? $kSolverEnabled : $kSolverDisabled; } } return $result; }