Tuesday, May 11, 2010

The start of another blog.

I use MEL daily and figured why not share something that learn everyday or just some cool uses for MEL that I find. So here goes the first post...

Filling in text fields with selection using textFieldButtonGrp
This is a very practical use for filling in a GUI quickly using the pickWalk command and some clever loops.

Lets start with an array:

string $array[] = {"Leg", "Knee", "Ankle"};
So now we want a GUI that displays the name in the label, a textField that loads in the selected joints, and it's corresponding children:
string $array[] = {"Leg", "Knee", "Ankle"};
window -t "Leg Setup Maker" tempWin;
for ($i=0;$i<size($array);$i++) {
int $numFields = `size($array)` - $i;
textFieldButtonGrp -cw 1 50 -l $array[$i] -text "" -buttonLabel "<<<"
-buttonCommand ("loadSel(" + $numFields + ")")
("txtFieldGrp" + $i);
showWindow tempWin;

Our GUI will now be made with whatever is contained in our array. Now all we need is our global procedure "loadSel" that we will be passing in how many times to loop to fill out the rest of our fields.
global proc loadSel(int $numChild) {
string $sel[] = `ls -sl`;
for ($i=0;$i<=$numChild;$i++) {
textFieldButtonGrp -e -text $sel[0] ("txtFieldGrp" + $i);
$sel = `pickWalk -d "down" $sel[0]`;

We get the selection with "ls -sl", the run the for loop for the number of buttons we have left to go through and fill them out with the children. Annnd done!