PDA

View Full Version : Have UI change depending on UI choices?


hellspawned
11-19-2012, 04:01 PM
Hi!

I'm making a script for a school task. The script is supposed to generate stuff based on the things you pick in the UI. Right now I'm stuck on setting up the UI.

I want the options for the different choices to be different, i.e. they require different controls. For generating a simple brick wall, i need an int slider for height, one for length, a float slider for edge bevel on the bricks and 2 radio buttons for picking the direction its gonna be generated in, while generating ground clutter only requires 4 float sliders - How wide an area is covered, x and z, size of the rocks and amount of rocks.

I tried to do this with an If/else if-statement within the UI code, checking the first radio button choice and creating the different controls based on that, but it doesn't work. It only showed the first option, no matter what radio button I pressed. So, what's a good way to set up that part of the UI?

bk3d
11-19-2012, 05:37 PM
Hi!

I'm making a script for a school task. The script is supposed to generate stuff based on the things you pick in the UI. Right now I'm stuck on setting up the UI.

I want the options for the different choices to be different, i.e. they require different controls. For generating a simple brick wall, i need an int slider for height, one for length, a float slider for edge bevel on the bricks and 2 radio buttons for picking the direction its gonna be generated in, while generating ground clutter only requires 4 float sliders - How wide an area is covered, x and z, size of the rocks and amount of rocks.

I tried to do this with an If/else if-statement within the UI code, checking the first radio button choice and creating the different controls based on that, but it doesn't work. It only showed the first option, no matter what radio button I pressed. So, what's a good way to set up that part of the UI?

I would create a function to change the UI. In that function you can set visible and not visible with the -vis flag of the differnt UI setups. Keep in mind that setting a UI element vis will propogate thru the childeren of the UI.

pseudo code:

radioButtonGrp -numberOfRadioButtons 2 -label "" -labelArray2 "Wall" "Debris" -sl 1 -cc("changeUI") radio_UIType;

columnLayout column_Wall;
button -l "create wall";
setParent..;

columnLayout column_Debris
button -l "create debris";
setParent..;


global proc changeUI()
{
$UI = `radioButtonGrp -q -sl radio_UIType`;

if ($UI == 1)
{
columnLayout -e -vis 1 column_Wall;
columnLayout -e -vis 0 column_Debris
}

if ($UI == 2)
{
columnLayout -e -vis 0 column_Wall;
columnLayout -e -vis 1 column_Debris
}
}

hellspawned
11-19-2012, 06:44 PM
Thanks for the answer!

A question: Don't I need to declare $ui as a variable? Or isn't it necessary in this case? And in that case, why is that?

Also, another question. Half of the time, my script refuses to recognize the custom sliders I've added.

The code looks like this:
floatSliderGrp
-label "Rock Size" -field true
-minValue 1.0 -maxValue 100.0
-value 1
myRockSlider1;

and returns: "// Error: Line 54: Object 'myFenceSlider1' not found. //"

However, when I copy virtually identical code (the only difference being the names) from another source, it has no problem with it. What is up with that?

bk3d
11-19-2012, 07:22 PM
Thanks for the answer!

A question: Don't I need to declare $ui as a variable? Or isn't it necessary in this case? And in that case, why is that?

Also, another question. Half of the time, my script refuses to recognize the custom sliders I've added.

The code looks like this:
floatSliderGrp
-label "Rock Size" -field true
-minValue 1.0 -maxValue 100.0
-value 1



myRockSlider1;

and returns: "// Error: Line 54: Object 'myFenceSlider1' not found. //"

However, when I copy virtually identical code (the only difference being the names) from another source, it has no problem with it. What is up with that?

im not sure why you are getting the error since you havent posted the whole code.. but for your slider UI myRockSlider1 is your UI variable. It is global so you can access that anywhere in your script just by querying it.

$RockSize = `floatSliderGrp -q -v myrockSlider1`;

hellspawned
11-19-2012, 07:41 PM
I just thought that I might've made a mistake in the declaration of that object. If that was the case, it would've been easier for someone more knowledgeable than I to find the error if I just posted the part that's giving me grief, rather than the whole shebang. Anyhow...

Full code as follows.
if ( `window -exists GenScriptWindow` )
deleteUI GenScriptWindow;

window -title "Stuff Generation Script" -widthHeight 300 300 GenScriptWindow;

formLayout -numberOfDivisions 200 myForm;

radioButtonGrp -vr -numberOfRadioButtons 3 -label "Select Type" -labelArray3 "Fence" "Scattered Rocks" "Brick Wall" -select 1 -cc("changeUI") myRadBtnGrp;

columnLayout columnFence;
floatSliderGrp -label "Fence Height" -field true -minValue 1.0 -maxValue 100.0 -value 1 myFenceSlider1;

floatSliderGrp -label "Fence Length" -field true -minValue 1.0 -maxValue 100.0 -value 1 myFenceSlider2;
setParent "myRadBtnGrp";

columnLayout columnRocks
floatSliderGrp -label "Rock Size" -field true -minValue 1.0 -maxValue 100.0 -value 1 myRockSlider1;

floatSliderGrp -label "Number of Rocks" -field true -minValue 1.0 -maxValue 100.0 -value 1 myRockSlider2;
setParent "myRadBtnGrp";

columnLayout columnBrick
floatSliderGrp -label "Wall Height" -field true -minValue 1.0 -maxValue 100.0 -value 1 myBrickSlider1;

intSliderGrp -label "Wall Length" -field true -minValue 1.0 -maxValue 100.0 -value 1 myBrickSlider2;
setParent "myRadBtnGrp";

button -label "Execute" -command "runGenScript()" myBtn1;

formLayout -edit
-attachForm myRadBtnGrp "top" 10
-attachForm myRadBtnGrp "left" 10

-attachForm myFenceSlider1 "top" 80
-attachForm myFenceSlider1 "left" 10
-attachForm myFenceSlider2 "top" 120
-attachForm myFenceSlider2 "left" 10

-attachForm myStoneSlider1 "top" 80
-attachForm myStoneSlider1 "left" 10
-attachForm myStoneSlider2 "top" 120
-attachForm myStoneSlider2 "left" 10

-attachForm myBrickSlider1 "top" 80
-attachForm myBrickSlider1 "left" 10
-attachForm myBrickSlider2 "top" 120
-attachForm myBrickSlider2 "left" 10

-attachForm myBtn1 "bottom" 10
-attachForm myBtn1 "left" 10
myForm;

global proc changeUI(int $uiType)
{
$uiType = `radioButtonGrp -q -sl myRadBtnGrp`;

if ($uiType == 1)
columnLayout -e -vis 1 columnFence;
columnLayout -e -vis 0 columnRocks;
columnLayout -e -vis 0 columnBrick;

if ($uiType == 2)
columnLayout -e -vis 0 columnFence;
columnLayout -e -vis 1 columnRocks;
columnLayout -e -vis 0 columnBrick;

if ($uiType == 3)
columnLayout -e -vis 0 columnFence;
columnLayout -e -vis 0 columnRocks;
columnLayout -e -vis 1 columnBrick;

}
showWindow GenScriptWindow;


And thanks for taking your time! :)

bk3d
11-20-2012, 01:32 AM
I acutally find formLayouts cumbersome so here is how i would set it up

if ( `window -exists GenScriptWindow` )
deleteUI GenScriptWindow;

window -title "Stuff Generation Script"GenScriptWindow;
columnLayout;
radioButtonGrp -vr -numberOfRadioButtons 3 -label "Select Type" -labelArray3 "Fence" "Scattered Rocks" "Brick Wall" -select 1 -cc("changeUI") myRadBtnGrp;

columnLayout -vis 1 columnFence;
floatSliderGrp -label "Fence Height" -field true -minValue 1.0 -maxValue 100.0 -value 1 myFenceSlider1;
floatSliderGrp -label "Fence Length" -field true -minValue 1.0 -maxValue 100.0 -value 1 myFenceSlider2;
setParent..;

columnLayout -vis 0 columnRocks;
floatSliderGrp -label "Rock Size" -field true -minValue 1.0 -maxValue 100.0 -value 1 myRockSlider1;
floatSliderGrp -label "Number of Rocks" -field true -minValue 1.0 -maxValue 100.0 -value 1 myRockSlider2;
setParent..;

columnLayout -vis 0 columnBrick;
floatSliderGrp -label "Wall Height" -field true -minValue 1.0 -maxValue 100.0 -value 1 myBrickSlider1;
intSliderGrp -label "Wall Length" -field true -minValue 1.0 -maxValue 100.0 -value 1 myBrickSlider2;
setParent..;

button -label "Execute" -command "runGenScript()" myBtn1;

setParent..;
global proc changeUI()
{
$uiType = `radioButtonGrp -q -sl myRadBtnGrp`;

if ($uiType == 1)
columnLayout -e -vis 1 columnFence;
columnLayout -e -vis 0 columnRocks;
columnLayout -e -vis 0 columnBrick;

if ($uiType == 2)
columnLayout -e -vis 0 columnFence;
columnLayout -e -vis 1 columnRocks;
columnLayout -e -vis 0 columnBrick;

if ($uiType == 3)
columnLayout -e -vis 0 columnFence;
columnLayout -e -vis 0 columnRocks;
columnLayout -e -vis 1 columnBrick;

}
showWindow GenScriptWindow;

hellspawned
11-20-2012, 10:10 AM
Ah, thanks a bunch! With curly brackets around the if statements, it worked perfectly :)

One last question, one of a more aesthetic nature.

http://imgur.com/H5cGYhttp://imgur.com/H5cGYhttp://imgur.com/H5cGY

This is the UI as it looks now. I can't seem to find a way to
A) Get the label for the first set of radio buttons above the buttons, instead of having it off to the side
B) Get the label of the last checkbox on the left side, to make the interface look less random.

CGTalk Moderation
11-20-2012, 10:10 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.