Page 1223 - Kitab3DsMax
P. 1223

Chapter 49: Automating with MAXScript
                                             Tutorial: Using variables
                                             In this tutorial, you learn more about variables in MAXScript by using them to manipulate an object in your scene.
                                             To use variables to manipulate scene objects, follow these steps:
                                                 1. Open the Teapot.max file from the Chap 49 directory on the DVD.
                                                    This file has a simple teapot object.

                                                 2. Right-click on the title for the Left viewport, and choose Views ➪ Extended ➪ MAXScript Listener
                                                    to open the MAXScript Listener window in the Left viewport.
                                                 3. Select the teapot object, type $, and press Enter.
                                                    Max displays information about the teapot. (Your numbers will probably be different depending
                                                    on where you placed your teapot.)
                                                 4. Type the following lines one at a time in the top pane to see the property values stored as part of
                                                    the teapot object:
                                                    $.position
                                                    $.wirecolor
                                                    $.radius
                                                    $.name
                                                    $.lid
                                                 5. Now type these lines, one at a time, to set the property values of the teapot object:
                                                    $.lid = false
                                                    $.position.x = -20
                                                    $.segs = 20
                                             Figure 49.13 shows the commands, their results in the MAXScript Listener window, and the resulting tea-
                                             pot object.
                                             Program flow and comments
                                             In general, when Max begins executing a script, it starts with the first line of the script, processes it, and
                                             then moves on to the next line. Execution of the script continues until no more lines are in the script file.
                                             (Later, you’ll look at some MAXScript keywords that let you change the flow of script execution.)
                                             Max lets you embed comments or notes in your script file to help explain what is happening. To insert a com-
                                             ment, precede it with two hyphens (--). When Max encounters the double hyphen, it skips the comment and
                                             everything else on that line and moves to the next line of the script. For example, in this line of MAXScript
                                                 $Torus01.pos = [0,0,0]   -- Move it back to the origin
                                             Max processes the first part of the line (and moves the object to the origin) and then moves on to the next
                                             line after it reaches the comment.
                                             Using comments in your MAXScript files is very important because as your scripts start to become complex,
                                             figuring out what is happening can get difficult. Also, when you come back a few months later to improve
                                             your script, comments will refresh your memory and help keep you from repeating the same mistakes you
                                             made the first time around.
                                     Note
                                     Because Max ignores anything after the double hyphen, you can use comments to temporarily remove MAXScript
                                     lines from your script. If something isn’t working right, you can comment out the lines that you want Max to skip.
                                     Later, when you want to add them back in, you don’t have to retype them. You can just remove the comment
                                     marks, and your script is back to normal. n
                                                                                                                      1175
   1218   1219   1220   1221   1222   1223   1224   1225   1226   1227   1228