Modifier : MAXWrapper and SpacewarpModifier : MAXWrapper

 

   

Modifier Classes - Quick Navigation

The Modifier and SpacewarpModifier families of classes can be created and added to an object’s modifier stack using the addModifier() or modPanel.addModToSelection() methods. Unless otherwise noted, the term modifier will be used to mean members of either class.

By making a single modifier and adding it to several objects, you are sharing the modifier between the objects, as you would by applying a modifier to a selection of objects in the 3ds Max user interface. The constructors in the following classes can take any of the listed properties as optional keyword arguments with the defaults as shown.

Accessing Existing Modifiers

Existing modifiers can be accessed in two ways:

Node.Property Access

Modifiers can be accessed as a property of a node.

When you access properties on a <node> scene object, such as its name, position, length etc, MAXScript will also consider modifiers on the object to be properties, for example:

$box001.heightsegs --get creation parameter
$box001.twist --get the twist modifier
$box001.twist.angle --the twist’s angle 

You can then access modifier properties as sub-properties on the modifier as shown. If the modifier name has spaces in it, you can use underscore ‘_’ as space convention that pathnames use, like this:

$box001.uvw_map --to get the ‘UVW Map’ modifier 

.Modifiers Array Access

The property access described above will work in simple situations, but there may be several modifiers with the same name, or a modifier with the same name as a creation parameter (the latter is always looked for first).

In this situation you can use the modifier array mechanism, which yields an array of modifiers you can index into in several ways:

$box001.modifiers --get the array or modifiers
$box001.modifiers[3] --get the 3rd modifier counted from top of the list
$box001.modifiers[#twist] --get the modifier named "twist" using name literal
$box001.modifiers["ffd 4x4x4"] --get the FFD named "ffs 4x4x4" using string
$box001.modifiers[bend] --get the Bend by class (Added in 3ds Max 2013) 

Looping Through The Modifiers

You can use a for loop over the .modifiers array to go through all existing modifiers and check their name, class and/or properties to find the one you need.

Accessing a Modifier By Index

You can access a modifier in the .modifiers array by its index.

The modifiers are listed as shown in the Modifier stack, indexed from top to bottom, starting with 1.

If the index is out of range, either higher than the number of modifiers in the array or less than 1, the value of undefined will be returned.

FOR LOOP AND INDEX EXAMPLES SETUP

t=teapot() --create a teapot
addmodifier t (bend angle:30) --add a Bend modifier with Angle 30
addmodifier t (bend angle:60 direction:90) --add a Bend modifier with angle 60 and dir 90
addmodifier t (twist angle:180) --add a Twist modifier with Angle 180

FOR LOOP AND INDEX EXAMPLES:

--The following will find all Bend modifiers with Angle less than 90 and change the Angle to 90
for m in t.modifiers where classof m == Bend and m.angle < 90 do m.angle = 90

--The following will find all modifiers (in this case both the Bends and the Twist)
--with an Angle property and change it to 0
for m in t.modifiers where isProperty m #Angle do m.angle = 0

--The following will delete modifiers that have a direction property other than 0.
--On our case this is the second, upper Bend modifier.
--Note that we must count backwards from bottom of the stack because deleting a modifier
--will renumber the modifiers array and we could otherwise miss a modifier:
for m = t.modifiers.count to 1 by -1 \
  where isProperty t.modifiers[m] #Direction and t.modifiers[m].direction != 0 do
    deleteModifier t m

Accessing a Modifier By Name Literal

You can access a modifier in the .modifiers array by name literal.

Use underscore ‘_’ in place of spaces in the name, like with properties access.

If two modifiers have the same name, the top-most will be returned.

If a modifier with the specified name does not exist in the array, the value of undefined will be returned.

Accessing a Modifier By Name String

You can access a modifier in the .modifiers array by name string.

The name string access is case-insensitive.

If two modifiers have the same name, the top-most will be returned.

If a modifier with the specified name does not exist in the array, the value of undefined will be returned.

NAME LITERAL AND NAME STRING ACCESS EXAMPLES

t=teapot() --create a teapot
addmodifier t (ffd_4x4x4()) --add a FFD 4x4x4 modifier with default name
addmodifier t (ffd_2x2x2 name:"My FFD") --add a FFD 2x2x2 modifier with custom name
addmodifier t (twist angle:90 name:"My Twist") --add a twist with custom name

t.modifiers[#ffd_4x4x4] --try to access by name literal
t.modifiers[#ffd_2x2x2] --try to access by name literal - that name does not exist!
t.modifiers[#My_FFD]    --try to access by the custom name - that works
t.modifiers[#My_Twist]  --try to access by the custom name - also works
	
t.modifiers["ffd 4x4x4"] --same as above, but with string, so we can use spaces
t.modifiers["ffd 2x2x2"] --that name does not exist, so we get undefined back
t.modifiers["My FFD"]    --this is the correct name, so we get it now
t.modifiers["My Twist"]  --this is also the correct name, so we get the Twist
t.modifiers["mY tWiSt"]  --the names are case-insensitive, so this returns the same Twist
t.modifiers["My_Twist"]  --we can even replace spaces with underscores in string names!
theName = #My_Twist      --in other words, if we have a name literal,
t.modifiers[theName]     --we can use it as name literal,
t.modifiers[theName as string] --or as string and both will produce the same result! 

MAXSCRIPT LISTENER OUTPUT:

$Teapot:Teapot001 @ [0.000000,0.000000,0.000000]
OK
OK
OK
FFD_4x4x4:FFD 4x4x4
undefined
FFD_2x2x2:My FFD
Twist:My Twist
FFD_4x4x4:FFD 4x4x4
undefined
FFD_2x2x2:My FFD
Twist:My Twist
Twist:My Twist
Twist:My Twist
Twist:My Twist
Twist:My Twist
OK

Accessing a Modifier By Class

In 3ds Max 2013 and higher, you can access a modifier in the .modifiers array using its class instead of its name.

If two modifiers have the same class, the top-most will be returned.

If a modifier with the specified class does not exist in the array, the value of undefined will be returned.

EXAMPLES

t=teapot() --create a teapot
addmodifier t (bend name:"MyBendAtBottom") --add a Bend modifier
addmodifier t (bend name:"MyBendOnTop") --add another Bend modifier
addmodifier t (twist name:"MyTwist") --add a Twist modifier
t.modifiers[twist] --access the Twist
t.modifiers[bend] --access the top-most Bend ("MyBendOnTop")
t.modifiers[skew] --undefined, because no Skew was added 

LISTENER OUTPUT:

$Teapot:Teapot001 @ [0.000000,0.000000,0.000000]
OK
OK
OK
Twist:MyTwist
Bend:MyBendOnTop
undefined

   

The classes derived directly from the Modifier and SpacewarpModifier classes are described in Modifier and SpacewarpModifier Types.

The properties, operators, and methods that are common to all classes derived directly from the Modifier and SpacewarpModifier classes are described in Modifier Common Properties, Operators, and Methods.

The Modifier and SpacewarpModifier classes are derived from the MAXWrapper class, and inherits the properties and methods defined for that class. These properties and methods are described in MAXWrapper Common Properties, Operators, and Methods.