|
|
|||||
Creating floating dialog boxes using MaxScript
Summary: This document summarizes the steps of creating a floating dialog box using MaxScript. A simple example function is also defined.
| Product(s) | Release(s) | Platform(s) |
| 3D Studio MAX (TM) | 2.0; 2.5 | Win95, WinNT |
| 3D Studio VIZ | 2.0 | Win95, WinNT |
| Audience: | For Public Distribution - Global | |
| Keywords: | MAXSCRIPT FLOATING DIALOG BOX SCRIPT FUNCTION 5486 | |
| Related documents: | None | |
| Document: US-XT-TD805486.DOC | Revision: A | |
| Creation date: October 7, 1998 | Last revised: October 20, 1998 | Expires: October 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.
Table of Contents
Overview
MaxScript routines can be executed from rollouts in the Utilities panel of the Command Panel, yet it is more convenient to access MaxScripts that are used often or ones that require a lot of user interaction from a floating dialog box. This document explains how to create a basic floating dialog box that executes a simple function.
Note: This document does not explain function definition or the MaxScript language in general. Its focus is the basic interface design of floating dialog boxes.
Components of the floating dialog box
The basic components of a floating dialog box are:
Note: For more information about the types of controls for dialog boxes, see the MaxScript Reference (Help > MaxScript Reference). Search under the index tab, for "rollout floater windows" or for "rollout user-interface items."
Creating a floating dialog box
2. Copy and paste the following text into the new MaxScript window:
resetMaxFile #noPrompt -- FUNCTION DECLARATIONS fn Stretcher arg = ( addModifier arg (stretch stretch:0.0) animate on ( at time 0 (arg.stretch.stretch = 0.0; arg.stretch.amplify = 0.0) at time 50 (arg.stretch.stretch = -1.0; arg.stretch.amplify =-20.0) at time 100 (arg.stretch.stretch = 0.0; arg.stretch.amplify =0.0) ) ) -- USER INTERFACE ITEMS FirstDialog = newRolloutFloater "Acme Flying Logo Dialog" 200 175 rollout FirstRollout "This is the first section:" ( button btn_one "Create Sphere" \ tooltip: "Press this button to create a sphere" \ pickbutton btn_two "Squash Object" \ tooltip: "Press this button to add the Stretch modifier" \ enabled:false \ on btn_one pressed do ( s = sphere radius:50 recenter:true btn_two.enabled = true btn_one.enabled = false ) on btn_two picked obj do ( Stretcher obj btn_two.text = obj.name btn_two.enabled = false ) ) rollout SecondRollout "This is the second section:" ( button go_away "Close" tooltip: "This will close your Floating Dialogorama" \ on go_away pressed do ( closeRolloutFloater FirstDialog ) ) addrollout FirstRollout FirstDialog addrollout SecondRollout FirstDialog3. From the new Script, go to the File menu > Save. Save the script as First Floater.ms
4. From the File menu > Evaluate All. This runs the script.
5. Choose the Create Sphere button. Notice that it becomes disabled once it is pressed.
Tip: Evaluation means running the script. A shortcut for evaluating one line of text in a script is to place the cursor at the end of that line in the script and press the Shift and Enter keys simultaneously. To evaluate multiple lines, highlight the lines and press the Shift and Enter keys simultaneously.
6. Choose the Squash Object button and select the sphere.
7. Press the Play button on the Time Controls. The sphere squashes and springs back to shape.
8. Choose Close to exit the dialog.
Script Layout Description
Each section of the script is explained.
The description of the code follows each section of code.
| resetMaxFile #noPrompt |
This resets the current session without further prompting to ensure a new start. This option can be commented.
Tip: "Commenting" is a method of including text in code that the program ignores. 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 dashes [ -- ]. Whatever follows the two dashes is ignored by MaxScript as it evaluates that line of code. Comments only last for one line of code. You will see many comments in MaxScripts; they are the programmer’s notes to you. In this example you could type [-- resetMaxFile #noPrompt] to "comment out" the reset command.
-- FUNCTION DECLARATIONS fn Stretcher arg = ( addModifier arg (stretch stretch:0.0) animate on ( at time 0 (arg.stretch.stretch = 0.0; arg.stretch.amplify = 0.0) at time 50 (arg.stretch.stretch = -1.0; arg.stretch.amplify = -20.0) at time 100 (arg.stretch.stretch = 0.0; arg.stretch.amplify = 0.0) ) ) |
This is a function definition section.
For a function to be available to all the rollouts in a dialog, it should
be defined at the head of the script. If the function is only necessary
for a local rollout, then it can be defined within that rollout. This function
squashes the sphere using the STRETCH modifier.
| -- USER INTERFACE ITEMS |
| FirstDialog = newRolloutFloater "Acme Flying Logo Dialog" 200 175 |
This is where the dialog is defined. The subsequent rollouts will be a part of this floating dialog.
rollout FirstRollout "This is the first section:" ( button btn_one "Create Sphere" \ tooltip: "Press this button to create a sphere" \ pickbutton btn_two "Squash Object" \ tooltip: "Press this button to add the Stretch modifier" \ enabled:false \ on btn_one pressed do ( s = sphere radius:50 recenter:true btn_two.enabled = true btn_one.enabled = false ) on btn_two picked obj do ( Stretcher obj btn_two.text = obj.name btn_two.enabled = false ) ) |
In the first rollout the buttons are defined, then the event handlers for those buttons get defined. Note that the user interface event handlers – what happens when the button is pressed – can either define an action (as in btn_one) or call a function (as in btn_two). Also note that the state of the buttons are interdependent. If feasible, it is a good idea to leave buttons disabled until they are needed. The tooltip property of the buttons is optional, but useful for users familiarizing themselves with your script.
rollout SecondRollout "This is the second section:" ( button go_away "Close" tooltip: "This will close your Floating Dialogorama" \ on go_away pressed do ( closeRolloutFloater FirstDialog ) ) |
This is the second rollout. It closes
the dialog box.
| addrollout FirstRollout FirstDialog |
| addrollout SecondRollout FirstDialog |
These commands add the rollouts to the floating dialog box.
Note: For more information about the design interface, see the MaxScript Reference (Help > MaxScript Reference). In the Index tab, search for "layout parameters."
| Was this article helpful?
(very helpful) 5 43 21 (not helpful) |
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