How do I instance Modifiers and Controllers inside the same object?

MAXScript FAQ > Working With Scene Nodes > How Do I instance Modifiers and Controllers inside the same object?

A user asked:

Is there a function for copying a modifier and then pasting an instance of it onto the same object? I can copy and paste it but not as an instance.

Answer:

Reading an existing modifier through MAXScript and applying the SAME modifier will create an instance automatically.

FOR EXAMPLE:

b = Box heightsegs:10 height:100--creates a high box
addModifier b (Bend())--adds a bend modifier to it
addModifier b (b.bend)--instances the same modifier on top 

So you just read ANY value in MAXScript - using it again means INSTANCE it.

IF YOU TRY

for i in selection do addModifier i (Bend())

you are adding a unique modifier to every object, because the constructor expression (Bend()) is evaluated n times where n is the number of selected objects.

BUT IF YOU USE

theBend = Bend()
for i in selection do addModifier i theBend

then you are creating a single modifier, storing it into a variable and then applying an instance of it to each object in the selection.

Even better, mapped operations are also good for instancing. The same result as above can be achieved with much less code:

FOR EXAMPLE

addModifier selection (Bend())

adds the SAME Bend modifier as instance to all selected objects, because the constructor expression (Bend()) is evaluated only once and is then applied in an internal loop as instance to every object in the collection.

Obviously, you can instance between objects, too.

You can also apply the same technique to controllers. For example, if you want to instance the controller of the X_Position and assign it to the Bend Angle, then you can say:

FOR EXAMPLE

theBox = Box heightsegs:10 height:100
theBox.bend.angle.controller = theBox.position.x_position.controller

Now if you move the object along X, the bend angle will change accordingly.

See Also