Creating and Assigning Materials

The Material class represents the materials you can assign to objects in 3ds Max. Classes derived directly from Material are Material Types, such as (but not limited to) Standard, Physical, and MultiMaterial. The classes derived from these are materials you can create and use in 3ds Max scenes.

Creating a material in pymxs invovles calling its constructor. For example:

>>> t = pymxs.runtime.teapot()
>>> m = pymxs.runtime.standardMaterial()
>>> t.material=m

Once a material is created, you can set its properties. For example:

>>> m.diffuse = pymxs.runtime.color(10,10,10)
>>> m.specular = pymxs.runtime.color(255,255,255)

For a complete example of creating and applying a material with pymxs, see \scripts\PythonSamples\Python3\pymxs\materials.py.

Working with the Material Editor

There are several interfaces that expose features in the legacy/compact editor and the Slate Material Editor. The MatEditor interface provides general methods for getting and setting the editor mode, and opening and closing the editor window, and works with both the compact editor and the Slate Material Editor. The SME interface has methods for working with the Slate Material Editor, while the medit interface works on the compact/legacy editor.

For example, to set the first slot in the compact material editor to a new Physical Material, and then open it:

>>> pymxs.runtime.MatEditor.mode = pymxs.runtime.name('basic')
>>> mat = pymxs.runtime.PhysicalMaterial()
>>> pymxs.runtime.setMeditMaterial(1, mat)
>>> pymxs.runtime.MatEditor.open()
True

Note that the first index for the material editor is 1 (not 0) because the method arguments get passed to MAXScript. If you are accessing the array of materials directly through pymxs, it is 0-based:

>>> pymxs.runtime.meditMaterials[0]
<PhysicalMaterial<PhysicalMaterial:Physical_Material>>