PDA

View Full Version : Updating checkBoxes


Sammy1
09-29-2009, 03:03 PM
I am working on a tool that for each dag in the scene creates a checkbox in a window. When the corresponding checkbox is checked, then the item is selected (put on the active list), and when the corresponding checkbox is unchecked then the dag is unselected. My problem is that if I select or unselect an dag in the scene with my mouse (or any other way that doesn't involve my window) the checkboxes don't reflect whether the dag is actually on the active list. Does anyone know a way on how to fix this?

if(`window -exists "checkBoxWindow"` == 1){
deleteUI "checkBoxWindow";
}
window checkBoxWindow;
columnLayout;
select -cl;
select -allDagObjects -vis;
string $scene[]= `ls -selection`;
string $checkBoxList[];
int $i;
for($i = 0; $i < size($scene); $i++)
{
select -cl;
//runs once each loop
while(true){
$checkBoxList[$i] = `checkBox -onc ("select -add " + $scene[$i]) -ofc ("select -d " + $scene[$i]) -label ("" + $scene[$i])`;
break;
}
}
showWindow;

Robert Bateman
09-29-2009, 04:07 PM
global proc doSomethingWhenSelectionChanges()
{

}

// set up the script job
scriptJob -event "SelectionChanged" "doSomethingWhenSelectionChanges";

Sammy1
09-29-2009, 09:49 PM
Thanks for your help. I just have one more question on this subject.

if(`window -exists "checkBoxWindow"` == 1){
deleteUI "checkBoxWindow";
}
window checkBoxWindow;
columnLayout;
select -cl;
select -allDagObjects -vis;
string $scene[]= `ls -selection`;
string $checkBoxList[];
int $i;
//invariant: ith iteration creates a checkbox for the ith dag in the scene
for($i = 0; $i < size($scene); $i++)
{
select -cl;
//runs once each loop: creates the checkbox in the gui
while(true){
$checkBoxList[$i] = `checkBox -onc ("select -add " + $scene[$i]) -ofc ("select -d " + $scene[$i]) -label ("" + $scene[$i])`;
break;
}
}
global proc somethingChanged(){
int $k;
string $selected[];
$selected = `selectedNodes -dagObjects`;
int $match; //using as a boolean
//looks at the kth dag in the scene and checks to see if it is selected.
//if yes then the corresponding checkbox should be checked, and if not then the
//checkbox should be unchecked
for($k=0; $k < size($scene); $k++){
$match = 0; //false
for( $dag in $selected ){
if(`strcmp $scene[$k] $dag` == 0){
$match = 1; //true
}
}
//if the dag is selected then its checkbox shoukd be checked and vice versa
checkBox $checkBoxList[$k] -value $match;
}
}
scriptJob -event "SelectionChanged" somethingChanged();
showWindow;
I'm getting errors saying that $checkBoxList abd $scene are undeclared in the somethingChanged procedure. How can I fix this since I want the same variables that I have in upper portions of my code.

mlefevre
09-30-2009, 09:17 AM
Hi,

You could try global variables.
Also,
$selected = `selectedNodes -dagObjects`;
returns an object with the pipe symbol, '|', and I'm not sure if you'd get the correct result using strcmp with a string of "|polySphere1" and "polySphere1".




if(`window -exists "checkBoxWindow"` == 1){
deleteUI "checkBoxWindow";
}
window checkBoxWindow;
columnLayout;
select -cl;
select -allDagObjects -vis;
global string $sceneObjects[];
$sceneObjects = `ls -selection`;
global string $checkBoxListA[];
print $checkBoxListA;
int $i;
//invariant: ith iteration creates a checkbox for the ith dag in the scene
for($i = 0; $i < size($sceneObjects); $i++)
{
select -cl;
//runs once each loop: creates the checkbox in the gui
while(true){
$checkBoxListA[$i] = `checkBox -onc ("select -add " + $sceneObjects[$i]) -ofc ("select -d " + $sceneObjects[$i]) -label ("" + $sceneObjects[$i])`;
break;
}
}
showWindow;
global proc somethingChanged(){
global string $sceneObjects[];
global string $checkBoxListA[];
int $k;
string $selected[];
$selected = `ls -sl`;
int $match; //using as a boolean
//looks at the kth dag in the scene and checks to see if it is selected.
//if yes then the corresponding checkbox should be checked, and if not then the
//checkbox should be unchecked
for($k=0; $k < size($sceneObjects); $k++){
$match = 0; //false
for( $dag in $selected ){
if(`strcmp $sceneObjects[$k] $dag` == 0){
$match = 1; //true
}
}
//if the dag is selected then its checkbox shoukd be checked and vice versa
checkBox -e -value $match $checkBoxListA[$k];
}
}
scriptJob -event "SelectionChanged" "somethingChanged()";


Good luck!

CGTalk Moderation
09-30-2009, 09:17 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.