Site Navigation

BackTechnical Solutions


Advanced Search
E-mail This Page

Using Case Expressions with MAXScript

Summary: This document introduces the MAXScript case expression by defining and discussing a script constructed with case expressions.
Product(s)

Release(s)

Platform(s)

3D Studio MAX (TM)

2.0; 2.5

Win95, Win98, WinNT

3D Studio VIZ

2.0

Win95, Win98, WinNT

Audience:

For Public Distribution - Global

Keywords:

CASE EXPRESSION MAX SCRIPT 5506

Related documents:

TD805507

Document: US-XT-TD805506.DOC

Revision: A

Creation date: November 4, 1998

Last revised: December 7, 1998 

Expires: December 31, 1999

The tips, tricks, examples and suggestions outlined in Autodesk Product Support technical documents are suggested for use at your own risk. Document contents are subject to change without notice. Autodesk is not responsible or liable for damage or events that may occur as a result of following suggestions from any Autodesk Product Support technical document.
© 1998 Autodesk. Autodesk and the Autodesk logo are registered trademarks of Autodesk Inc. All other brand names, product names or trademarks belong to their respective holders.

Overview

The ‘Case Expression’ is used to select which expression from a set of expressions will be evaluated. Among other things, case expressions allow the user to choose between blocks of code to execute. Conceptually, the Case Expression is identical with the ‘If Expression’, but can be easier to use when there are many expressions to choose from, since ‘Case’ abbreviates the ‘If’ test.

This document demonstrates the case expression in relation to radio buttons. First the document steps through evaluating the case expression, then analyzes each section of the script.

This document does not cover User Interface Design or the MAXScript language in general. For more information on the case expression, see the MAXScript Reference in the help menu of 3D Studio MAX. Related technical documents are listed in the document description header, above.

Defining the Script

To run the script again, first close the ‘Best Case Scenario’ floating dialog box. From the file menu of the new script, select Evaluate All.

Script Analysis

resetMaxFile #noPrompt

This line resets the current session without further prompting to ensure a new start. This option can be commented out.


Tip: "Commenting out" is a method of including text in code that the program will ignore. This is useful for commenting on lines of the code as you write it, and for disabling parts of a routine without deleting the code. In MAXScript, the comment symbol is two hyphens. [ -- ].MAXScript ignores whatever follows the two dashes as it evaluates that line of code. Comments will only apply to one line of code.
-- USER INTERFACE ITEMS
CaseTest = newRolloutFloater "Worst Case Scenario" 250 150
This begins the user interface definition section for the floating dialog box. This line of code defines the dialog box within which the rollouts will be included and then sizes it.
rollout gender_issue "Describe yourself"
(
radioButtons gender "Are you a: " labels:#("man",\
    "woman", "child", "other")
This defines the only rollout for the floating dialog box. Four radio buttons are defined with labels of man, woman, child, and other. Notice the single backslash character after the "man" label. This is a line continuation character: MAXScript continues to read the next line as if it was part the first line. For more information on continuation characters, search the MAXScript reference, index tab for "Source Code Layout and Continuation Lines."
On btn_gender changed state do (
When any of the radio buttons are picked, the case expression is evaluated.
case state of
    (
        1: (c = cone () )
        2: (s = sphere () )
        3: (b = box () )
        4: (t = spindle radius:20 height:42 cap_height:15)
    )
Depending on the button pressed, the corresponding case is evaluated. The radio button state is compared with the labeled expressions. For example, ‘woman’ is radio button state 2 , so the expression labeled 2 is evaluated. In this example, in the case that radio button is woman, make a sphere; in the case that radio button is child, make a box.

When there is a long list of expressions to choose from, the ‘Case’ form is more convenient to read and write than the ‘If’ form, although the two forms amount to the same thing. For example, if the radio button is woman, make a sphere; if the radio button is child, then make a box.

Btn_gender.enabled = false
After any of the radio buttons are selected, they are all disabled.
Addrollout rgender_issue CaseTest
The rollout is included in the floating dialog box.

Note: For a more involved script using the case expression, refer to Technical Document 5507 (TD805507) Using Radio Buttons with Case Expressions.
 Was this article helpful?
(very helpful) 421 (not helpful) 
Top of Page

Home | Products | Tech Assist | Autodesk | Prof Net | Search | Sitemap | Purchase

©Copyright 1998 Autodesk, Inc. All rights reserved.
Reproduction or copying of images is prohibited.
Autodesk Privacy Policy

Comment on Technical Assistance