Maya Training

Introduction to Hard Surface Modeling

Maya Training

Interiors and Furniture Vol 1 & 2 - Modeling & Cloth

Maya Training

Shading, Lighting and Rendering the Bedroom in MR

Maya Training

Robot volume one - Modeling with animation in mind

Maya Training

Spach-Alspaugh House the complete courseware

Maya Training

Burt The Cartoon Dinosaur Vol 01 - Modeling

New Maya Training

Robot Volume 02 - Hybrid Rigging
You are here > Home > SimplyMaya Community Forums
Loading

Welcome to Simply Maya

Please Sign in or Sign up for an account

Member Login

Lost your password?

Not a member yet? Sign Up!

Old 08-03-2006, 09:43 AM   #1
skywola
Registered User
 
skywola's Avatar
 
Join Date: Jan 2004
Location: Tempe, Arizona, USA
Posts: 224
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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 . . .


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, 48 views)
__________________
"The Sage as an Astronomer: If you still see the stars as something above you, you lack the eye of knowledge." Friedrich Nietzsche
skywola is offline   Reply With Quote
Old 09-03-2006, 01:22 AM   #2
vladimirjp
Subscriber
 
vladimirjp's Avatar
 
Join Date: Jun 2003
Location: stuck in the 90's boston, USA
Posts: 1,871
Thanks: 0
Thanked 4 Times in 3 Posts
Default

cant u just copy and paste the commands of the original script?

or make your script call the joint orient proc
__________________
Image dump
vladimirjp is offline   Reply With Quote
Old 09-03-2006, 06:09 AM   #3
skywola
Registered User
 
skywola's Avatar
 
Join Date: Jan 2004
Location: Tempe, Arizona, USA
Posts: 224
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
skywola is offline   Reply With Quote

A little bit about who we are
Links you might find useful
Catch up with SimplyMaya
SimplyMaya specialises in Maya tutorials. We offer over 1,000 individual Maya training videos, ranging from basic Maya tutorials through to intermediate Maya tutorials. Our tutorials are created by instructors with industry experience and are designed to get you up and running in Maya quickly without making it seem like hard work.

Copyright © 1999-2015 SimplyMaya - vBulletin® Copyright © 2000-2015, Jelsoft Enterprises Ltd.