|
|||||||||||||||||||||||||||||
CHAPTER 14
|
| |
![]() | TIP If you want a variable to be saved with a scene, you need to use Persistent Global variables. See Chapter 17 for more information. |
When you create a simple object, as in the box example above, its created with a default size, position, etc. You will most likely want to access and change this data. But in order to do so, you need to know which data is available for you. Why? Because each and every object has different properties. For instance, a sphere has a radius, but a box has height, length, and width. To list an objects properties, you use the SHOWPROPERTIES command. Once you have typed a = box(), then if you type showproperties a MAXScript will list the properties in the Listener, as shown in Figure 14.1.
FIGURE
14.1 SHOWPROPERTIES result
You can access any of this boxs properties by typing a.property (for example, a.height). You can also change the values of each property, typing a.property = value (a.height = 60).
You can set an object property at the time of creation, specifying the properties and their
values: a = box height:60 width:30 length:40
Theres no limit in the number of properties you can define, and if any property is not listed, it will be set to its default value. If a property is listed but does not relate to that object, its discarded.
| |
![]() | TIP Besides using SHOWPROPERTIES, you can also record creating an object and changing its parameters to the values you need. This makes it easier for you to manipulate objects, and keeps you from having to memorize thousands of commands. |
Sometimes you do not create objects in MAXScript, but you need to process objects already created. To do so, you need to learn how to select and manipulate selections, and how to refer to objects by name.
You can access any object by its name simply by adding the $ symbol before the object name. For instance if you have an object named Wall, you can access it using $wall.
| |
![]() | NOTE Object names in MAXScript are not case-sensitive. If you have two objects, one named Ball and another named ball (and MAX, unfortunately, allows you to name as many objects as you wish with the same name), MAXScript will not distinguish between them even if you use $ball or $Ball. |
You can also assign variables that point to named objects in the scene, like a = $wall. From then on, you can access the object as a or as $wall.
| |
![]() | WARNING If the object is renamed, you cannot use $name any more. But if you assign $name to a variable and later rename the object, this variable can be used. For example, you could create a box named Box01, type var = $box01, and then rename Box01. If you type var, MAXScript shows you the box properties; if you type $Box01 it returns undefined. |
Sometimes you dont know a specific object name, or you do not want to use a specific object, but you want to use an object selection. You can refer to selections in two ways: using selection, which is an array of all selected objects, or using the $ symbol.
There are some peculiarities in selections that need to be addressed. It is very important to know how many objects have been selected, using $.count or selection.count. This is important because if selection.count returns only one object selected, this object can be accessed simply using $. On the other hand, if it returns more than one object, you must use selection[i] to access each object in the selection array.
Manipulating Selections
You can manipulate selections by adding or removing objects from the selection. To remove an object from the selection, use the DESELECT command; to add objects to a selection, use the SELECTMORE command. To simply discard any selection and select a specific object, you can use the SELECT command.
| |
![]() | TIP You can use wildcards when specifying object names. For instance, if you want to select all objects that start with B, you can use select $B*. If you want to select all objects that end in 01 you can use $*01. You can also use the ? wildcard to represent a single character. |
Previous | Table of Contents | Next |
© 2000, Frol (selection, edition, publication)
![]() |