These commands let you pause your script to get input from the user. To create complex custom user interfaces, see Creating interfaces.
Asking a question with confirmDialog
The confirmDialog command creates a modal window with a message to the user and any number of buttons.
The window disappears when the user presses any button or clicks the window’s close button.
- Use the message flag to set the text string that appears above the buttons.
- Add a button flag with the title string of each button.
- Use the defaultButton flag to specify which button corresponds to the Enter key.
- Use the cancelButton flag to specify which button corresponds to the Esc key.
- If the user clicks a button, the name of the button is returned.
- If the user clicks the window’s close button, the string specified by the
dismissString flag is returned.
confirmDialog -title "Confirm" -message "Are you sure?" -button "OK" -button "Cancel" -defaultButton "OK" -cancelButton "Cancel" -dismissString "Cancel";
Letting the user choose a file with fileDialog
The fileDialog command shows a file open dialog window. See fileDialog in the Maya Mel Commands documentation
- Use the
directoryMask flag to specify the starting directory and a filename filter. If you don’t use this flag, the file dialog starts in the current working directory.
The string may contain a path name, and must contain a wildcard file specifier. (for example "*.cc" or "/usr/u/*").
- The command returns the path of the file the user chose, or an empty string if the user cancels the file dialog.
fileDialog -directoryMask "*.txt"
Getting a string with promptDialog
The promptDialog command creates a window with a message to the user, a text box, and any number of buttons. See promptDialog in the Maya Mel Commands documentation.
- Use the title flag to set the window title. Use the message flag to set the string that appears above the text box and buttons.
- Use the text flag to set the initial contents of the text box. Use the scrollableField flag to change the text box to a multi-line scroll field.
- Add a button flag with the title string of each button.
- Use the defaultButton flag to specify which button corresponds to the Enter key.
- Use the cancelButton flag to specify which button corresponds to the Esc key.
- If the user clicks a button, the name of the button is returned.
- If the user clicks the window’s close button, the string specified by the dismissString flag is returned.
- After the command returns, use the command again with
query flag and the
text flag to get the text the user entered.
// Show the dialog box: string $text; string $result = `promptDialog -title "Rename Object" -message "Enter Name:" -button "OK" -button "Cancel" -defaultButton "OK" -cancelButton "Cancel" -dismissString "Cancel"`; // Use the command again in query mode to // get the text: if ($result == "OK") { $text = `promptDialog -query -text`; }