Hey all-
I am working on a script that gives you a window which lists all of the shaders by type, and I am getting some strange behavior. When I run the script, everything seems to be fine, but when you click through the various types of shaders, some of the shaders are listed below several types. Specifically, some of the phongs are listed both under phong and lambert. These shaders were brought in through an import via obj, and this might be the issue, but I am not sure why... Here is the script:
[codebox]{
// build window
if (window -ex listShaders\_Win
)
{
deleteUI listShaders\_Win;
}
$win = window -w 400 -h 320-t "List Shaders by Type" listShaders\_Win
;
$oFrm = frameLayout -lv 0 -mw 10 -mh 10
;
$oRow = rowColumnLayout
-numberOfRows 3
-rh 1 70
-rh 2 250
-rh 3 150
;
$cmdFrm =frameLayout -l "Command" -mh 10 -mw 10
;
$cmdCol = columnLayout
;
$cmd_RBG = radioButtonGrp -sl 1 -nrb 3 -labelArray3 "assign" "Select Objects" "Graph Shader" cmdRBG
;
setParent $oRow;
$listFrm =frameLayout -l "Lists" -mh 10 -mw 10
;
$listCol = columnLayout
;
$mRow = rowColumnLayout
-numberOfColumns 2
-cw 1 190
-cw 2 190
;
$shaderTypeCol = columnLayout
;
$shaderTypeTSL =textScrollList -sc "{textScrollList -e -ra setMemTSL; textScrollList -e -ra shaderTSL;
$type =
textScrollList -q -si shaderTypeTSL;string $curShaders[] =
ls -type $type;
for ($y in $curShaders){textScrollList -e -append $y shaderTSL;}}" -w 150 -h 200 shaderTypeTSL
;
setParent $mRow;
$shaderCol = columnLayout
;
$shaderTSL =textScrollList -dcc "{int $cmd =
radioButtonGrp -q -sl cmdRBG ;
string $shader[] =
textScrollList -q -si shaderTSL; shaderListCmd $cmd $shader[0];}" -w 150 -h 200 shaderTSL
;
setParent $oRow;
$setMemFrm =frameLayout -l "Set Members" -mh 10 -mw 10
;
$setMemCol = columnLayout
;
$setMemTSL =textScrollList -sc "{string $shader[] =
textScrollList -q -si shaderTSL;
$sg =
returnSG\_sp $shader[0];selectSetMems $sg ;}"-ams 1 -w 380 -h 100 setMemTSL
;
setParent $mRow;
showWindow $win;
}
// fill lists
// fill shader type list
{
string $shaderTypesTemp[] =listNodeTypes "shader"
;
string $curShaderType;
string $shaderTypes[];
string $shaders[];
int $i = 0;
for ($sh in $shaderTypesTemp)
{
string $curTypes[] =`ls -type $sh`;
int $size = size($curTypes);
//print $size;
if ($size > 0)
{
for ($c in $curTypes)
{
if ($curShaderType != $sh)
{
$curShaderType = $sh;
$shaderTypes[$i] = $sh;
$i++;
}
}
}
}
//print $shaderTypes;
int $i = 0;
for ($s in $shaderTypes)
{
string $curShaders[] =`ls -type $s`;
int $size = size($curShaders);
if ($size > 0)
{
for ($c in $curShaders)
{
$shaders[$i] = $c;
$i++;
}
}
}
//print $shaders;
for ($st in $shaderTypes )
{
textScrollList -e -append $st shaderTypeTSL;
}
}
// return the Shading Engine associated with the selected Shader
global proc string returnSG_sp (string $shader)
{
$cons =listConnections -d on $shader
;
string $sg;
for ($co in $cons )
{
//print ($co + "\n");
$conType =`objectType $co`;
if ($conType == "shadingEngine")
{
return $co;
}
}
}
// assign shader to the selected objects
global proc assignShaderFromList (string $sg)
{
sets -e -forceElement $sg;
}
// select objects associated with the shader
global proc selectShaderObjectsFromList (string $sg)
{
hyperShade -objects $sg;
}
// graph the selected shader
global proc graphShaderFromList (string $shader)
{
string $sel[] =ls -sl
;
select -r $shader;
string $hpShd = hyperShadePanelName
;
hyperShadePanelGraphCommand("hyperShadePanel1", "showUpAndDownstream");
select -r $sel;
}
// build the shader list command based on the RGB selection
global proc shaderListCmd ( int $cmd, string $shader)
{
string $sg = returnSG\_sp $shader
;
//print ($sg + "\n");
if ($cmd == 1)
{
assignShaderFromList $sg;
updateSetMems $sg;
selectSetMems $sg;
}
else if ($cmd == 2)
{
selectShaderObjectsFromList $sg;
updateSetMems $sg;
selectSetMems $sg;
}
else if ($cmd == 3)
{
graphShaderFromList $shader;
updateSetMems $sg;
selectSetMems $sg;
}
}
// update set members list at the bottom of the window
global proc updateSetMems (string $sg)
{
textScrollList -e -ra setMemTSL;
textScrollList -e -append "<--remove all from selection-->" setMemTSL;
$setMems =sets -q $sg
;
for ($set in $setMems)
{
textScrollList -e -append $set setMemTSL;
}
//textScrollList -e -append "" setMemTSL;
}
// add selected items from the setMemsTSL to the selection list
global proc selectSetMems ( string $sg )
{
$setMems =sets -q $sg
;
string $si[] =textScrollList -q -si setMemTSL
;
for ($s in $si)
{
if ( $s == "<--remove all from selection-->")
{
for ($set in $setMems)
{
select -d $set;
textScrollList -e -da setMemTSL;
}
}
else
{
select -add $s;
}
}
}
// not used yet
global proc deselectSetMems ()
{
string $si =textScrollList -q -si setMemTSL
;
select -add $si;
}
[/codebox]