Skip to content

Instantly share code, notes, and snippets.

@hmasato
Last active December 18, 2015 03:39
Show Gist options
  • Select an option

  • Save hmasato/5719626 to your computer and use it in GitHub Desktop.

Select an option

Save hmasato/5719626 to your computer and use it in GitHub Desktop.
[MAYA] _nodeList
proc string[] _GUI(string $func)
{
if(`window -exists ($func+"Win")`) deleteUI ($func+"Win");
window -title $func ($func+"Win");
paneLayout -cn "horizontal2" -paneSize 1 100 15 -paneSize 2 100 85;
columnLayout -h 50 -adj 1;
rowColumnLayout -h 50 -nc 2 -cw 1 60 -cw 2 160 -cat 1 "right" 0;
text -l "Node Name"; string $txt=`textField -text "*" ($func+"Tfld")`;
text -l "Node Type"; string $txt2=`textField -text "*" ($func+"Tfld2")`;
setParent ..;
string $btn=`button -l "Refresh" ($func+"Btn")`;
setParent ..;
string $tlist=`textScrollList -allowMultiSelection 0 -deselectAll ($func+"Tbox")`;
setParent..;
showWindow;
return({$tlist, $txt2, $btn, $txt});
}
global proc _nodeList_Update(string $txtScrl, string $key)
{
string $nodes[]=`ls -showType`;
string $types[]={};
for($i=0; $i<size($nodes); $i+=2){
if(!gmatch($nodes[$i+1], $key)) continue;
$types[size($types)]=$nodes[$i+1];
}
clear $nodes;
$types=stringArrayRemoveDuplicates($types);
$types=sort($types);
textScrollList -e -removeAll $txtScrl;
for($type in $types){
textScrollList -e -append $type $txtScrl;
}
clear $types;
}
global proc _nodeList_Exec(int $mode, string $typ, string $key)
{
if($key=="") $key="*";
string $nodes[]={};
string $buf[]=`ls -type $typ`;
for($node in $buf){
if(!gmatch($node, $key)) continue;
$nodes[size($nodes)]=$node;
}
clear $buf;
switch($mode){
case 1: select -r $nodes;
break;
default: {
print ("\n----------["+$typ+"]\n");
print $nodes;
} break;
}
clear $nodes;
}
global proc _nodeList()
{
string $func="_nodeList";
string $ctls[]=_GUI($func);
//initial update
_nodeList_Update($ctls[0], "*");
//make command for controls
string $ccmd=""
+"{string $key=`textField -q -text "+$ctls[1]
+"`; _nodeList_Update(\""+$ctls[0]+"\", $key);}"
;
string $scmd=""
+"{string $typ[]=`textScrollList -q -si "+$ctls[0]+"`;"
+"string $key=`textField -q -text "+$ctls[3]+"`;"
+"string $key=`textField -q -text "+$ctls[3]+"`;"
+"_nodeList_Exec(0, $typ[0], $key);}"
;
string $dcmd=""
+"{string $typ[]=`textScrollList -q -si "+$ctls[0]+"`;"
+"string $key=`textField -q -text "+$ctls[3]+"`;"
+"_nodeList_Exec(1, $typ[0], $key);}"
;
//set command for controls
button -e -c $ccmd $ctls[2];
textField -e -changeCommand $ccmd $ctls[1];
textField -e -changeCommand $scmd $ctls[3];
textScrollList -e -sc $scmd -dcc $dcmd $ctls[0];
}
_nodeList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment