PDA

View Full Version : Ask for variable value for running script in MEL menu?


schizofrantic
11-19-2010, 01:31 AM
I know you can just launch a popup and have the popup execute the command, but I am lazy and want to just have a popup that requires no extra step if that's possible.

Does that make any sense? I mean that I need to have for example a skin cluster name, but I want some command that just fills a variable name say to an environment variable and then runs the command once it's done.

Not sure if this even exists in MEL or not and couldn't find anything but it would save me a couple hours of futzing so maybe it's supported?

schizofrantic
11-19-2010, 09:46 AM
proc string promptVariable(string $promptString)
{
string $command = "promptDialog -message \""+$promptString+"\" -button \"Ok\" -button \"Cancel\" -defaultButton \"Ok\" -cancelButton \"Cancel\" -dismissString \"Cancel\"";
eval($command);
string $value = `promptDialog -query`;
return $value;
}

proc string promptVariableWithDefault(string $promptString, string $defaultText)
{
string $command = "promptDialog -message \""+$promptString+"\" -text \""+$defaultText+"\"-button \"Ok\" -button \"Cancel\" -defaultButton \"Ok\" -cancelButton \"Cancel\" -dismissString \"Cancel\"";
eval($command);
string $value = `promptDialog -query`;
return $value;
}

ewerybody
11-22-2010, 12:43 PM
I use similar functions too. In mel you could put the arguments in a string array and read from that. this way you have variable inputs...
You could actually omit the eval:

global proc string promptVariable(string $promptString)
{
promptDialog -message $promptString -button "Ok" -button "Cancel" -defaultButton "Ok" -cancelButton "Cancel" -dismissString "Cancel";
return `promptDialog -query`;
}

global proc string promptVariableWithDefault(string $promptString, string $defaultText)
{
promptDialog -message $promptString -text $defaultText -button "Ok" -button "Cancel" -defaultButton "Ok" -cancelButton "Cancel" -dismissString "Cancel";
return `promptDialog -query`;
}


But that stuff is well built-in into python:
def promptVariable(message='',title='Maya',buttons=['Ok','Cancel']):
pressed = mc.promptDialog(
title=title,
message=message,
button=buttons,
defaultButton=buttons[0],
cancelButton=buttons[1],
dismissString=buttons[1])

result = mc.promptDialog(q=1,text=1)
return result,pressed

promptResult = promptVariable()
promptResult = promptVariable(buttons = ['Yes','No'])
promptResult = promptVariable(title = 'The Big Question!?', message = 'What is the meaning of all this?', buttons = ['Yes','42','No','brbokithxbbq']) ;D

CGTalk Moderation
11-22-2010, 12:43 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.