Well if you need the color of button changing automatically when you select a sphere or anything for that matter then you will have to use "scriptJobs" ... If you're new to mel scripting then you might find it a little difficult to set this up but anyways here is an eg:
after you have initialised the scriptJob's its really important to kill them else they keep eating system resources. So you will have to have a kill scripts procedure.
eg:
global proc killScrJob(int $scrJob1, int $scrJob2) { scriptJob -k $scrJob1; scriptJob -k $scrJob2; }
hehe.. my reply was more for amitkhanna than for you. I just read what youwanted to do:
But your definition isn't final: I try to sketch the situation:
You got a scripted window with a button in it, right? Now you select a sphere and the button shall turn blue just as you selected it?
Or is there something else you do to do the check? Of course you can make another button and a procedure that checks if there is a special object in your selection: e.g.:
CODE global proc checkMySelection () { //ls :very usefull list-command// -sl is for selection// "[]" because ls returns an array string $sel[] = ls -sl; string $itemToCheck = "pSphere1"; int $itemIsInSel; //if you set an int its 0 by default for ($item in $sel) { if ($item == $itemToCheck) $itemIsInSel = 1; } if ($itemIsInSel) print "Item IS in your selection!\n"; // or turn your button color else print "Item is NOT in your selection!\n"; // or turn your button color }
But if you want it like described first: To change the color of the button as you pick it your object of desire thats an event that has nothing to do with you window at all. You have to create the window with a scriptJob parented to it, so this job acts if the window is open and is killed if you close the window.
Its really not a big deal. You gonna dig it!! CODE { if (window -ex myWindow) deleteUI myWindow; window myWindow; columnLayout; button -bgc 1 1 1 myButton;
global proc checkMySelection () { //ls :very usefull list-command// -sl is for selection// "[]" because ls returns an array string $sel[] = ls -sl; string $itemToCheck = "pSphere1"; int $itemIsInSel; //if you set an int its 0 by default for ($item in $sel) { if ($item == $itemToCheck) { $itemIsInSel = 1; } } if ($itemIsInSel) { // sometimes the buttons are not updated ot once so make it invisible first // and visible again button -e -vis 0 -bgc 0 0 1 myButton; button -e -vis 1 myButton; } else { button -e -vis 0 -bgc 0 1 0 myButton; button -e -vis 1 myButton; } }
I changesd my script a little as you pointed, So i dont need any extra scriptJob to kill the first two. And its just working fine
I had this extra killing procedure in one of my other script which just wouldnt kill the script jobs on window closure, so i added this extra killing. But anyways its working fine for this example....
But i couldnt understand what you are trying to explain in your last rep.. thoughi understand what the code you wroe does.
it worked perfectly (after a few failed attempt...
I managed to have a window with 3 buttons, each button as a process to select one of the sphere (i needed to have a process so i can use the "shift" key to -add select if i wanted to.)
And all the buttons work correctly and change color if one or all the spheres are selected.
Thanks alot everyone who answered; it was very interesting!