Page 1227 - Kitab3DsMax
P. 1227

Chapter 49: Automating with MAXScript
                                             After this block of MAXScript, the variable b would have the value of 3 because the expression (a == 5)
                                            evaluated to false. Consequently, Max executed the MAXScript in the else section of the statement.
                                             Collections and arrays
                                             MAXScript has some very useful features to help you manipulate groups of objects. A group of objects is
                                             called a collection. You can think of a collection as a bag that holds a bunch of objects or variables. The
                                             things in the bag are in no particular order; they’re just grouped together.
                                             You can use collections to work with groups of a particular type of object. For example, the MAXScript
                                                 a = $pokey*
                                                 a.wirecolor = red
                                             creates a collection that contains every object in your scene whose name starts with “Pokey” and makes
                                             every object in that collection turn red.
                                             MAXScript has several built-in collections that you might find useful, such as cameras and lights, containing
                                             all the cameras and lights in your scene. So
                                                 delete lights
                                             removes all the light objects from your scene (which may or may not be a good idea).
                                             An array is a type of collection in which all the objects are in a fixed order, and you can access each mem-
                                             ber of the array by an index. For example
                                                 a = #()     -- creates an empty array to use
                                                 a[1] = 5
                                                 a[2] = 10
                                                 a[5] = 12
                                                 a
                                             After the last line, Max prints out the current value for the array:
                                                 #(5, 10, undefined, undefined, 12)
                                             Notice that Max makes the array big enough to hold however many elements you want to put in it, and that
                                             if you don’t put anything in one of the positions, Max automatically puts in undefined, which simply
                                             means that array location has no value at all.
                                             One last useful trick is that Max lets you use the as keyword to convert from a collection to an array:
                                                 LightArray = (lights as array)
                                             Max takes the built-in collection of lights, converts it to an array, and names the array LightArray.
                                            The members of an array or a collection don’t all have to have the same data type, so it’s completely valid to
                                            have an array with numbers, strings, and objects, like this:

                                                 A = #(5,”Mr. Nutty”,box radius:5)
                                     Note
                                     You can use the as MAXScript keyword to convert between data types. For example, (5 as string) converts the
                                     number 5 to the string “5,” and (5 as float) converts the whole number 5 to the floating-point number 5.0. n




                                                                                                                      1179
   1222   1223   1224   1225   1226   1227   1228   1229   1230   1231   1232