MAXScript FAQ > Accessing Object Properties > How do I change a property in multiple objects at once? |
One of the most often used applications of MAXScript is the mass-changing of object properties. This can save tremendous amounts of clicks and time.
To change a property in multiple objects, you need to:
The simplest situation imaginable is a selection of similar objects. For example, a large number of sphere primitives. MAXScript lets you easily access the current selection in the scene. In addition, an object property assignment is "mappable". This means that MAXScript applies the value on the right side of the assignment operator '=' to every single object in the selection automatically without the need of an explicit MAXScript for loop. See What Are Mapped Operations in MAXScript? for more details on mapped operations.
In case you have selected some object that does not have a property called radius such as, a Box primitive or some EditableMesh object, the above code causes an error:
In such a case, you need to make sure that the collection of objects is filtered by your script before an assignment is made. See the For Loop topic for more information. A possible way is:
If you want to change the radius of any object in the scene that has such a property instead of selecting objects manually, you can let MAXScript filter the scene for you. This affects all Spheres, GeoSpheres, Cylinders, and so on, but ignores any Boxes that do not have a "radius" property.
If you want to affect only the GeoSpheres in the scene and exclude all other classes, you can check the class of the objects instead. In this case, you do not have to check for a property named "radius" because any GeoSphere has this property. The classOf function returns the object's class, so you can compare it to the class you want to affect.
If you have no idea what the correct MAXScript name of a property is, you can either consult this Help File or use the showProperties inspector function in the Listener to print a list of all exposed object properties.