PDA

View Full Version : Learning MEL - can't figure out UI


LisaMAnd
12-27-2010, 06:07 AM
Hi everyone,

I'm afraid I'm new to MEL and having trouble getting a UI to work. The script here is just supposed to take a joint and split it into even segments.

There are a couple problems- I wanted a checkbox to change which procedure is executed (either splitting the original joint or making a new hierarchy) and I wanted a slider to change the number segments. Neither of these elements are working so I commented out the checkbox and figured I'd concentrate on getting the number of segments to work.

Right now, if I specify a number for $segmentOpt it'll work- but it won't pull a number from the slider.

Sorry if this is a super basic question. I'm getting pretty lost here.



Also: Just a side note- I've been basing what I'm doing off of some of Jason Schleifer, Duncan Skertchly, and my MEL Scripting for Maya Animators book's code- so if something works they should get the credit and if something doesn't belong or is broken it's probably mine!

Any help is appreciated,
-Lisa


global proc LA_splitJointUI()
{
//Build the interface window
string $splitJointWindow = `window -t "Split Joint UI"`;


string $form = `formLayout -numberOfDivisions 100`;

$segments = `intSliderGrp -field true -l "Segments" -min 2 -max 25 slider1`;
$button1 = `button -l "Split Joints"`;
$button2 = `button -l "Cancel"`;
//$checkBox = `checkBox -l "Create as New Joint Hierarchy"`;
/* -onCommand
"button -edit -command (\"LA_splitNewJoint \" + $segmentOpt) $button1"
-offCommand
"button -edit -command (\"LA_splitJoint \" + $segmentOpt) $button1"`;
*/
formLayout -edit

-attachForm $segments top 25
-af $segments left 25

//-af $checkBox top 75
//-af $checkBox left 100

-af $button1 bottom 10
-af $button1 left 15

-af $button2 bottom 10
-af $button2 left 110

$form;

// get the value from the slider

int $segmentOpt = `intSliderGrp -q -value slider1`;

// set up the buttons
button -edit -command ("deleteUI \"" + $splitJointWindow + "\"") $button2;
button -edit -command ("LA_splitNewJoint " + $segmentOpt) $button1;


/*checkBox -onCommand
"button -edit -command (\"LA_splitNewJoint \" + $segmentOpt) $button1"
-offCommand
"button -edit -command (\"LA_splitJoint \" + $segmentOpt) $button1"
$checkBox;
*/

showWindow $splitJointWindow;
}

James-Arlyle
12-29-2010, 08:33 PM
I think I see the problem.

The problem is that you're only setting the value for $segmentOpt once; namely, when the UI is built and shown. It's never reset when you press the button.

Instead of the code as you have it, it'd be better if you removed the int argument from LA_splitNewJoint and just queried the intSliderGrp from inside the procedure.

So instead of this in LA_splitJointUI:

// get the value from the slider
int $segmentOpt = `intSliderGrp -q -value slider1`;

// set up the buttons
button -edit -command ("deleteUI \"" + $splitJointWindow + "\"") $button2;
button -edit -command ("LA_splitNewJoint " + $segmentOpt) $button1;

Just say this:

// set up the buttons
button -edit -command ("deleteUI \"" + $splitJointWindow + "\"") $button2;
button -edit -command ("LA_splitNewJoint ") $button1;

And then change the start of LA_splitNewJoint to:

global proc LA_splitNewJoint ()
{
// This proc creates a new joint chain that is
// split into the specified number of segments.
//
// VARIABLES
//
int $numSegments = `intSliderGrp -q -value slider1`;



That should work...

I hope that helps.

LisaMAnd
12-30-2010, 04:09 PM
Oh, okay! Got it now.

Thanks so much for the help!

CGTalk Moderation
12-30-2010, 04:09 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.