//script weightChanger
//Author : wuzzie
//Corrected by Tom Kluyskens June 17 99 mailto:tkluyskens@aw.sgi.com
//Creates a window where you can change the weight of CV:s for both curves and surfaces
//If you have one CV selected the window will display the weight for that CV.
//if you select more than one CV the window will display the average weight.
//Limitations : You can only set weights for one object at a time.
//Construction history dont work with weights (see realease Notes for maya)
global proc weightChange()
{
float $weightOrCv[];
if (window -ex weightWindow
) $weightOrCv = weightOrCv 1 0
;
else $weightOrCv = weightOrCv 1 1
;
string $nurbsObject[] = ls -hl
;
if ( size( $nurbsObject) > 1) error "SELECT MAX 1 OBJECT!";
int $numCvs = size( $weightOrCv);
string $label;
if ($weightOrCv[0] == -1) $label = "SELECT CV!";
else if ( $numCvs ==1) $label = "weight";
else $label = "average weight";
float $value = 0;
int $i = 0;
if ($weightOrCv[0] == -1) $value =0 ;
else
{
for ( $i = 0; $i < $numCvs; $i++)
{
$value += $weightOrCv[ $i ];
}
$value /= $numCvs;
}
if (window -ex weightWindow
)
{
text -e -label $label weightText;
floatField -e -v $value weightField;
string $command;
if ($weightOrCv[0] == -1) $command = "error "SELECT CV!" ";
else $command = ("setWeight " + $nurbsObject[0] +" " + $numCvs +" weightField");
floatField -e -cc $command weightField;
}
else
{
window -title "CV weighter" weightWindow;
rowLayout;
rowColumnLayout -nc 2;
text -label $label weightText;
floatField -v $value weightField;
string $command = ("setWeight " + $nurbsObject[0] +" " + $numCvs +" weightField");
floatField -e -cc $command weightField;
scriptJob -p "weightWindow" -e "SelectionChanged" weightChange;
showWindow;
}
}
global proc setWeight(string $nurbsObject, int $numCvs, string $name)
{
float $value = floatField -q -v $name
;
float $Cv[] = weightOrCv 0 0
;
int $i = 0;
for ($i = 0; $i < $numCvs; $i++)
{
setAttr ($nurbsObject +".wt[" + $Cv[$i] + "]") $value ;
}
}
global proc float[] weightOrCv( int $choice, int $error) {
string $selectedCvs[] = filterExpand -sm 28
;
if ( ($error==1) && (size( $selectedCvs) == 0) ) error "SELECT CV!";
if ( ($error==0) && (size( $selectedCvs) == 0) ) return {-1};
int $type;
string $selected[] = ls -hl -dag -type nurbsSurface
;
if ( ! ($selected[0] =="") ) $type =0;
else { $selected=ls -hl -dag -type nurbsCurve
; $type = 1; }
int $cvsPerU;
int $cvsPerV;
if ($type == 0)
{
int $spansUV[2] = getAttr ( $selected[0] +".spansUV" )
;
int $degreeUV[2] = getAttr ($selected[0] +".degreeUV")
;
$cvsPerU = $spansUV[0] +$degreeUV[0];
$cvsPerV = $spansUV[1] +$degreeUV[1];
}
int $i;
float $weightOrCv[];
string $splitStrings[];
float $Cv;
for ($i = 0; $i < (size( $selectedCvs) ); $i++)
{
tokenize $selectedCvs[ $i ] "[]" $splitStrings;
if ( $type)
{
if ( $choice == 1) $weightOrCv[ $i ] =`getAttr ( $selected[0] +".wt[" +$splitStrings[1] +"]" )`;
else $weightOrCv[ $i ] = $splitStrings[1];
}
else
{
$Cv = $cvsPerV * (float) $splitStrings[1] + (float) $splitStrings[2];
if ( $choice == 1) $weightOrCv[ $i ] = `getAttr ( $selected[0] + ".wt[" + $Cv +"]" )`;
else $weightOrCv[ $i] = $Cv;
}
}
return $weightOrCv;
}