PDA

View Full Version : How to pass a value from a layout control?


nessus
05-04-2006, 06:52 AM
I am still very new to the MEL layout scripting part.
as i am making a very simple slider control in the GUI, something like this:

colorSliderGrp -label "Color" -rgb 0 0 0;

my question is when user sliding the control so the value changes, how do i get a hold of the value whatever the user changes to, and use it to set something.

for example, if i wanna use this slider as a light color control, so whatever user changes the slider, i will be able to capture it and set this value to a light.

DezFX
05-04-2006, 07:25 AM
You can use the -changeCommand flag to execute a string/command when the value of your slider is changed. You can also give the slider a name as the last argument and then query that elf name to check its values. Elf commands use the last non-flag argument as the name of the control. That gives you access to your control with the -query flag.

colorSliderGrp -label "Color" -changeCommand "printColor" -rgb 0 0 0 mySlider;
global proc printColor()
{
float $color[] = `colorSliderGrp -query -rgb mySlider`;
print ( "RGB value = " + $color[0] + ", " + $color[1] + ", " + $color[2] + "\n" );
}

nessus
05-04-2006, 07:52 AM
You can use the -changeCommand flag to execute a string/command when the value of your slider is changed. You can also give the slider a name as the last argument and then query that elf name to check its values. Elf commands use the last non-flag argument as the name of the control. That gives you access to your control with the -query flag.

colorSliderGrp -label "Color" -changeCommand "printColor" -rgb 0 0 0 mySlider;
global proc printColor()
{
float $color[] = `colorSliderGrp -query -rgb mySlider`;
print ( "RGB value = " + $color[0] + ", " + $color[1] + ", " + $color[2] + "\n" );
}

thank you DezFX!! i never knew that you can actually call a control from ourside of its procrdure, and i just found out about it 15 min ago. so now i can just create a control, name it and call it from another procedure. so the -q flag definitely works in this case, thank you!!!

goleafsgo
05-04-2006, 02:25 PM
Changing values in a callback will work but there are controls that are designed to do what you want. The colorSliderGrp is a general control, but the attrColorSliderGrp lets you automatically "attach" to a color attribute of an object. So if you want a control to modify the color attribute of a light then you can do this:


{
// Put the name of the object that you want to modify here.
string $objName = "directionalLight1";

window;
columnLayout;
attrColorSliderGrp -at ($objName + ".color");
showWindow;
}

CGTalk Moderation
05-04-2006, 02:25 PM
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.