Introduction to Maya - Modeling Fundamentals Vol 2
This course will look in the fundamentals of modeling in Maya with an emphasis on creating good topology. It's aimed at people that have some modeling experience in Maya but are having trouble with complex objects.
# 1 08-03-2006 , 09:43 AM
skywola's Avatar
Registered User
Join Date: Jan 2004
Location: Tempe, Arizona, USA
Posts: 224

Toggling a button ON - OFF

In another thread, JDigital did me the favor of mentioning the jsOrientJointUI script. . . . I had been looking for a script that could use a toggle button function, because I wanted to write one. I had been contemplating writing one for the Walkerman program that I wrote, but found that it would be impractical for that particular application, mainly because I was considering toggling a key-unkey function, but once the frame changed, I would have had to update every function that was keyable, so there was no point in persueing that.

Anyway the joint orient function fits the bill, so here is the main modifications I added to it.

It had two buttons, and ON button and an OFF button. I removed anything in the script referring to the OFF button, and removed the line of code that created he ON button, then I added this code:

// Create button with the toggle command
string $button = `button -label "On" toggle`;
button -edit -command ("toggleButton " + $button) $button;

Note that the first line of code names the button "toggle"

Then I added this procedure:

global proc toggleButton (string $whichButton) {
string $labelA; string $labelB; string $currentLabel;
$labelA = "On";
$labelB = "Off";
$currentLabel = `button -query -label $whichButton`;
if ($currentLabel != $labelA){
button -edit -label $labelA $whichButton;
jsDisplayAxisOnOff 1; // command to toggle on
} else {
button -edit -label $labelB $whichButton;
jsDisplayAxisOnOff 0; // command to toggle off
}
}


The tricky part of this procedure is that it must contain a command for whatever you want to do in your procedure, so as the code stands, you could not just create a generic toggleButton procedure, as the code is written. You be able to do it by passing in the commands as parameters I suppose, but when I am coding, as a general rule, I keep it simple, then later on when I feel energetic, I look for ways to improve the code.

Anyways as it stands, the procedure is imbedded in the jsOrientJointUI script, so it can call the "jsDisplayAxisOnOff 0;"
and "jsDisplayAxisOnOff 1;" without bothering to pass the parameters into the procedure. Maybe I'll get energetic later and write a generic toggleButton procedure that can be outside of the script. . . .

The new script, after my hacking on it I named jsOrientJointUIR
and will provide it for anyone who wants to look at it or try it out. . . .

Maybe someone else will feel energitic before I do and write the toggleButton script so it includes the command parameters . . .
user added image

BTW, I tried contacting the original author of this function, as there was an email listed for him, but the email address is evidently out of date. . . .

Attached Files
File Type: mel jsorientjointuir.mel (14.4 KB, 559 views)

"The Sage as an Astronomer: If you still see the stars as something above you, you lack the eye of knowledge." Friedrich Nietzsche
# 2 09-03-2006 , 01:22 AM
vladimirjp's Avatar
Subscriber
Join Date: Jun 2003
Location: stuck in the 90's boston, USA
Posts: 1,871
cant u just copy and paste the commands of the original script?

or make your script call the joint orient proc

# 3 09-03-2006 , 06:09 AM
skywola's Avatar
Registered User
Join Date: Jan 2004
Location: Tempe, Arizona, USA
Posts: 224
I guess I have been staying up to late and can no longer afford to pay attention . . . .

I don't see a need to pass parameters, as this toggleButton procedure is just calling another global procedure, so it works well as it stands.

Because of that, there is no need to make the script call the joint orient proc, it is good as it stands. My coding was good, but my analysis of it afterward was flawed . . . .

I usually go to bed around 12:00pm, but some nights I wake up at about 2:00AM, and then stay up coding or goofing around till about 4:00AM, then go back to bed and get up at about 8:30, go to work at 9:45 on the days I work and get home about 10:30PM . . . . goofy scedule but I like it.

I guess what is important is that you DO have to have particular commands for each click of the button if you are going to create a toggle button, and most likely you would want the commands to invoke another procedure. The code should be good enough as an example for anyone who wants to create one for their own purposes.


"The Sage as an Astronomer: If you still see the stars as something above you, you lack the eye of knowledge." Friedrich Nietzsche
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads