Here’s one of several name handling tools I’ve knocked out recently. Select any source object with left or right in its name and then a target object. The target will be renamed to that of the source with the opposite side.
For instance. If you select left_ulna and then select another joint and run the script the target joint will become right_ulna.
-----snip-----
proc int itemNthString (string $item, string $array[])
{
int $x;
int $theIndex = -1;
for ($x=0; $x<size($array); $x++)
{
if ($array[$x] == $item)
{
$theIndex = $x;
break;
}
}
return ($theIndex);
}
proc int stringWordPosition (string $item, string $matchString, string $wordChar){
string $tokenList[];
int $position;
tokenize $item $wordChar $tokenList;
$position = (`itemNthString $matchString $tokenList` + 1);
return $position;
}
proc int stringContains (string $theString, string $item){
string $matchString = ($item + “+”);
int $returnInt = 0;
if (`match $matchString $theString` == $item){
$returnInt = 1;
}
return $returnInt;
}
global proc string stringReplaceNthWord (string $item, string $replace, int $position, string $wordChar){
string $tokenList[];
string $returnString;
int $x, $y;
tokenize $item $wordChar $tokenList;
$y = size($tokenList);
for ($x=0; $x<$y; $x++){
if ($x != ($position -1)){ //is this replace or copy?
if ($x != ($y-1)) //is this the last word?
{$returnString += ($tokenList[$x] + $wordChar);} //if not, then it's x + a wordChar
else
{$returnString += $tokenList[$x];} //else, it's just x
}
else{ //replace
if ($x != ($y-1))
{$returnString += ($replace + $wordChar);}
else
{$returnString += $replace;}
}
}
return $returnString;
}
global proc liftNflopName (){
string $sel[] = ls-sl
;
string $side;
string $flopName;
int $position;
if (`stringContains $sel[0] "left"` == 1){
$side = "left";
$position = `stringWordPosition $sel[0] $side "_"`;
$flopName = `stringReplaceNthWord $sel[0] "right" $position "_"`;
}
if (`stringContains $sel[0] "right"` == 1){
$side = "right";
$position = `stringWordPosition $sel[0] $side "_"`;
$flopName = `stringReplaceNthWord $sel[0] "left" $position "_"`;
}
rename $sel[1] $flopName;
}
-jl