Created
June 6, 2013 05:59
-
-
Save hmasato/5719609 to your computer and use it in GitHub Desktop.
[MAYA] _nodePanel (_nodeList + ChannelBox)
This file contains hidden or 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
| proc string[] _GUI(string $func) | |
| { | |
| if(`window -exists ($func+"Win")`) deleteUI ($func+"Win"); | |
| window -title $func ($func+"Win"); | |
| paneLayout -w 200 -cn "left3" | |
| -paneSize 1 50 15 | |
| -paneSize 2 50 100 | |
| -paneSize 3 50 85; | |
| columnLayout -w 100 -h 50 -adj 1; | |
| string $sbtn=`button -l "Selection" -bgc 0.6 0.9 0.9 | |
| -c "_nodePanel_Selection();" ($func+"Sel"+"Btn")`; | |
| 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 ..; | |
| channelBox -w 100; | |
| string $tlist=`textScrollList -allowMultiSelection 0 -deselectAll ($func+"Tbox")`; | |
| setParent..; | |
| showWindow; | |
| return({$tlist, $txt2, $btn, $txt}); | |
| } | |
| proc _checkAttr(string $items[]) | |
| { | |
| if(size($items)<1) return; | |
| string $key="NODE"; | |
| string $keyGrp="___"+$key+"_GRP___"; | |
| string $keySet="___"+$key+"_SET___"; | |
| string $node=""; | |
| string $item=$items[0]; | |
| if(objExists($keySet)){ | |
| string $buf[]=`listRelatives -p $item`; | |
| if($keyGrp==$buf[0] || `sets -isMember $keySet $item`){ | |
| if(size($items)==1) return; | |
| $item=$items[1]; | |
| } | |
| } | |
| if(objExists($keySet)){ | |
| string $typs[]=`sets -q $keySet`; | |
| for($typ in $typs){ | |
| if(nodeType($typ)==nodeType($item)){ | |
| $node=$typ; | |
| break; | |
| } | |
| } | |
| } | |
| if($node==""){ | |
| if(!objExists($keyGrp)){ | |
| createNode -n $keyGrp transform; | |
| hide $keyGrp; | |
| } | |
| $node=`createNode -skipSelect (nodeType($item))`; | |
| string $buf[]=`listRelatives -p $node`; | |
| if(size($buf)>0){ | |
| $node=`rename -ignoreShape ($node) ($key+"_"+nodeType($item)+"#")`; | |
| parent -add -shape $node $keyGrp; | |
| parent -rm -shape ($buf[0]+"|"+$node); | |
| }else{ | |
| $node=`rename -ignoreShape ($node) ($key+"_"+nodeType($item)+"#")`; | |
| if(nodeType($item)=="transform") parent $node $keyGrp; | |
| } | |
| string $ds[]=`listAttr -cb -s -v -r -w -c -m $node`; | |
| string $nIs[]=`listAttr -s -v -r -w -c -m $node`; | |
| string $ns[]=stringArrayRemove($ds, $nIs); | |
| clear $ds; | |
| clear $nIs; | |
| $ns=sort($ns); | |
| for($non in $ns) setAttr -k 1 ($node+"."+$non); | |
| clear $ns; | |
| if(objExists($keySet)) sets -add $keySet $node; | |
| else sets -text "gCharacterSet" -n $keySet $node; | |
| } | |
| string $ks[]=`listAttr -k -s -v -r -w -c -m $node`; | |
| for($k in $ks){ | |
| connectAttr -f ($item+"."+$k) ($node+"."+$k); | |
| disconnectAttr ($item+"."+$k) ($node+"."+$k); | |
| } | |
| select -r $items; | |
| select -deselect $keyGrp; | |
| select -deselect $node; | |
| select -add $node; | |
| } | |
| global proc _nodePanel_Selection() | |
| { | |
| string $sels[]=`ls -sl -long`; | |
| _checkAttr($sels); | |
| } | |
| global proc _nodePanel_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 _nodePanel_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; | |
| _checkAttr($nodes); | |
| } break; | |
| default: { | |
| print ("\n----------["+$typ+"]\n"); | |
| print $nodes; | |
| } break; | |
| } | |
| clear $nodes; | |
| } | |
| global proc _nodePanel() | |
| { | |
| string $func="_nodePanel"; | |
| string $ctls[]=_GUI($func); | |
| //initial update | |
| _nodePanel_Update($ctls[0], "*"); | |
| //make command for controls | |
| string $ccmd="" | |
| +"{string $key=`textField -q -text "+$ctls[1] | |
| +"`; _nodePanel_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]+"`;" | |
| +"_nodePanel_Exec(0, $typ[0], $key);}" | |
| ; | |
| string $dcmd="" | |
| +"{string $typ[]=`textScrollList -q -si "+$ctls[0]+"`;" | |
| +"string $key=`textField -q -text "+$ctls[3]+"`;" | |
| +"_nodePanel_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]; | |
| } | |
| _nodePanel(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment