PDA

View Full Version : Buttons and procedures


Xinos
10-24-2010, 01:42 PM
I am trying to clean up a script by not having all of my buttons call upon it's own procedure, when they all contain nearly identical code. What I want to do is have the procedure accept an argument, like a string, but I am only running into syntax errors.

This code does not work, but you should be able to see what it is I want to do:

button -label "Up" -c "Direction('UP')" UpButton;
proc string Direction(string $direction){}


The trouble seems to be that the -command flag uses "quotation marks" which means I can't use those for the string.

NaughtyNathan
10-24-2010, 02:14 PM
a few things;
1) procs called by UI controls MUST be global.
2) you don't use single quotes ' in MEL
3) you don't need to call procs using ( ) in MEL
4) you can use " inside strings, you just have to "escape" them using \


global proc string Direction(string $direction){}

button -label "Up" -c "Direction UP" UpButton; // will work fine
button -label "Go Up" -c "Direction \"Go Up\"" UpButton; // will work fine too.
:nathaN

Xinos
10-24-2010, 02:46 PM
Thank you very much!

petemolinero
10-24-2010, 06:43 PM
a few things;
1) procs called by UI controls MUST be global.


It makes sense why it would be that way, however I have used non-global procs with a UI before and have not run in to any issue..

NaughtyNathan
10-24-2010, 09:25 PM
...I have used non-global procs with a UI before and have not run in to any issue.

not in MEL you haven't.. it's just not possible.
Don't forget, non-global (local) procs are only possible inside a saved script file, and any proc defined inside Maya's interface (in the script Editor, shelf button or hotkey) is automatically global.

:nathaN

CGTalk Moderation
10-24-2010, 09: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.