Created
November 14, 2014 01:17
-
-
Save AndrewtConroy/fee7a3092e31235990c6 to your computer and use it in GitHub Desktop.
TSM IK FK Switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global proc TSM2_FKIKSwitch() | |
{ | |
int $cycleCheckState; | |
$cycleCheckState = `cycleCheck -q -e`; | |
if ($cycleCheckState == 1) | |
cycleCheck -e off; | |
int $i; | |
string $selNodes[] = `selectedNodes`; | |
string $buffer[]; | |
int $numTokens = 0; | |
$numTokens = `tokenize $selNodes[0] "|" $buffer`; | |
string $theNode = $buffer[$numTokens-1]; | |
string $ns = ""; | |
$numTokens = `tokenize $theNode ":" $buffer`; | |
$theNode = $buffer[ $numTokens-1 ]; | |
if( $numTokens > 1 ) | |
{ | |
for( $i = 0; $i < (size($buffer) - 1); $i++ ) | |
{ | |
$ns += $buffer[$i]; | |
$ns += ":"; | |
} | |
} | |
$numTokens = `tokenize $theNode "_" $buffer`; | |
string $sysPref = $buffer[0]; | |
string $switchAttribute = $sysPref + "_FKIK"; | |
string $upperBody = $ns + "Upper_Body"; | |
string $userswitch = $upperBody + "." + $switchAttribute; | |
int $currentMode = `getAttr $userswitch`; | |
string $controlSet; | |
if( $currentMode == 0 ) | |
{ | |
$controlSet = $ns + $sysPref + "_IK_Controls"; | |
} | |
else | |
{ | |
$controlSet = $ns + $sysPref + "_FK_Controls"; | |
} | |
select $controlSet; | |
string $controls[] = `selectedNodes`; | |
for( $i = 0; $i < size($controls); $i++ ) | |
{ | |
string $control = $controls[$i]; | |
$numTokens = `tokenize $control "|" $buffer`; | |
$control = $buffer[$numTokens-1]; | |
string $switch = $control + "_SWITCH"; | |
if( `objExists $switch` ) | |
{ | |
string $controlAttributes[] = `listAttr -k $control`; | |
string $switchAttributes[] = `listAttr -k $switch`; | |
int $j; | |
for( $j = 0; $j < size($controlAttributes); $j++ ) | |
{ | |
if( $controlAttributes[$j] == "Reposition" ) | |
{ | |
$j++; | |
} | |
string $attributeToSet = $control + "." + $controlAttributes[$j]; | |
int $foundAttribute = 0; | |
int $k; | |
for( $k = 0; $k < size($switchAttributes); $k++ ) | |
{ | |
if( $controlAttributes[$j] == $switchAttributes[$k] ) | |
{ | |
$foundAttribute = 1; | |
string $attributeToGet = $switch + "." + $switchAttributes[$k]; | |
float $valueOfAttribute = `getAttr $attributeToGet`; | |
setAttr $attributeToSet $valueOfAttribute; | |
} | |
} | |
if( $foundAttribute == 0 ) | |
{ | |
setAttr $attributeToSet 0; | |
} | |
setKeyframe $attributeToSet; | |
} | |
} | |
} | |
if( $currentMode == 0 ) | |
{ | |
$currentMode = 1; | |
} | |
else | |
{ | |
$currentMode = 0; | |
} | |
setAttr $userswitch $currentMode; | |
setKeyframe $userswitch; | |
$keytime = `findKeyframe -which previous -attribute $switchAttribute -animation objects $upperBody`; | |
$now = `currentTime -query`; | |
if( $keytime == $now ) | |
{ | |
setKeyframe -time 0 $userswitch; | |
$keytime = 0; | |
} | |
keyTangent -time $keytime -outTangentType step -attribute $switchAttribute - animation objects $upperBody; | |
if ($cycleCheckState == 1) | |
cycleCheck -e on; | |
select -clear; | |
} | |
TSM2_FKIKSwitch; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment