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 in the daily work is the mass-changing of object properties. This can save tremendous amounts of clicks and time.
To change a property in multiple objects, you obviously need to:
The simplest situation imaginable would be 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 will apply 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 which does not have a property called radius, like a Box primitive or some EditableMesh object, the above code will cause an error:
In such case you would have to make sure the collection of objects is filtered by your script before an assignment is made. See the For Loop topic for more info. A possible way would be
If you want to change the radius of any object in the scene that has such property instead of selecting objects manually, you can let MAXScript filter the scene for you. This will affect all Spheres, GeoSpheres, Cylinders etc. and ignore any Boxes etc. that do not have a "radius" property.
If you want to affect only the GeoSpheres in the scene and exclude all other classes, you could check the class of the objects instead. In this case, you don't have to check for a property named "radius" since 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.