MAXScript Message and Query Dialogs

These functions let you display a message box or yes/no query dialog from within MAXScript.

messageBox <message_string> [optional arguments - see below]

Displays a modal message box containing the message string and an OK button.

queryBox <message_string> [optional arguments - see below]

Displays a modal message that contains Yes and No buttons. The queryBox() function returns true if the user clicks Yes and false if the user clicks No.

yesNoCancelBox <message_string> [optional arguments - see below] 

Displays a modal message with Yes, No, and Cancel buttons. The yesNoCancelBox() function returns #yes, #no or #cancel depending on which button the user selects.

cancelTryContinueBox <message_string> [optional arguments - see below] 

Displays a modal message box with Cancel, Try Again, and Continue buttons. This dialog returns #cancel, #tryAgain, or #continue, depending which button the user selects. Available in 3ds Max 2020.1 Update and higher.

retryIgnoreAbortBox <message_string> [optional arguments - see below] 

Displays a modal message box with Retry, Ignore, and Abort buttons. This dialog returns #retry, #ignore, or #abort, depending on which button the user selects. Available in 3ds Max 2020.1 Update and higher.

okCancelBox <message_string> [optional arguments - see below] 

Displays a modal message box with Ok and Cancel buttons. This dialog returns #ok or #cancel, depending on which button the user selects. Available in 3ds Max 2020.1 Update and higher.

retryCancelBox <message_string> [optional arguments - see below] 

Displays a modal message box with Retry and Cancel buttons. This dialog returns #retry or #cancel, depending on which button the user selects. Available in 3ds Max 2020.1 Update and higher.

Common optional dialog box arguments

All dialog box types support these common optional arguments.

 [title:<window_title_string>] [beep:<boolean>] \
   [icon:(#question|#information|#warning|#critical)] [defaultButton:<int>] \
   [dontShowAgain:&<variable>]  [helpID:<int>] [showHoldButton:<boolean>] \
   [parent:<int_ptr>] [extraFlags:<int>] 

title:<window_title_string> - specifies the dialog window title. The default, if unspecified is "MAXScript".

beep:<boolean> - specifies whether to make a beep sound when displayed, and whether to display an icon. The default is true.

These options are available in 3ds Max 2020.1 Update and higher:

icon:(#question|#information|#warning|#critical) - specifies an icon to display to override the default. The default depends on the type of message box being displayed. To show no icon, set beep to false.

defaultButton:<int> - specifies the index of the default button (the button already selected that will push when the user hits enter). The default is 1.

dontShowAgain:&<variable> - supports a "Don't Show Again" checkbox. The <variable> passed by reference returns true if the checkbox is checked.

helpID:<int> - when specified, adds a Help button to the dialog, and specifies the ID of a help topic to show when the user presses the button. See the <maxsdk>\include\contextids.h for a list of defined help topic IDs. Note that the dialogs do not support pressing F1 to invoke this help ID.

showHoldButton:<boolean> - indicates whether to display a "Hold/OK" button. If the user clicks this button, the dialog returns #hold.

parent:<int_ptr> - specifies the parent HWND of the dialog. By default this is the main 3ds Max window.

Note: This option causes slightly different behavior depending on whether the dialog is Qt-based (the default) or Win32-based (see flags below). By default, the parent window and other windows cannot be manipulated. For Win32-based dialogs, only the parent window is "locked", other windows can be manipulated.

extraFlags:<int> - a bit field of flags that can be combined to provide extra functionality. See the MSDN MessageBox function documentation for a description of these flag values.

FOR EXAMPLE:

messageBox "You shouldn't have done that"
if queryBox "Do you want to continue?" beep:false then...

In some cases, MAXScript statements occurring after a statement containing one of the above dialog function calls may be executed before they are supposed to be.

For example, if your execute:

SCRIPT:

for _t=0 to 3 do
(
messagebox "Press Me"
format "_t= %\n" _t
)
print "Should print last"

THE LISTENER WILL SHOW:

_t= 0
"Should print last"
"Should print last"
_t= 1
_t= 2
_t= 3

The MessageBox will be displayed 4 times, once each time before the value of _t is printed to Listener!

The reason for this is that Listener is looking for expressions to compile and run in a background thread. In the above example there are 2 expressions - the for loop expression and the final print expression. The messageBox() function goes on waiting for and processing UI events in the main UI thread, but the compiler has already compiled ahead and scheduled the print "Should print last".

To prevent this out-of-order execution, you need to bracket the script in parenthesis. This will force the sequencing to be correct because the script would now contain a single expression rather than two.