Scripts For 3D Artists

Material Library

NOTE: In 3ds Max there is a global variable called “sceneMaterials” that contains all the current scene materials. However since at least Max 2009 there is a bug that causes the sceneMaterials variable to not properly update when, for example, scripts add/remove materials. This can (and most likely will at some point) cause incorrect results when using scripts that deal with adding/removing/listing materials.

If you find incorrect results (such as a material that should no longer exist) there is an easy solution. In order to properly update the sceneMaterials variable simply apply a new material using the material editor. Here is the process I like to use: Take a piece of geometry in your scene and sample its material into one of the editor slots. Now apply an unused material to the geometry (like one of the default materials) and then apply its original material.

Material library UI preview

Load Material Library: Opens a material library as the current material library. If you already have a library you want to make renders of or apply to the scene then you MUST use this method. Do NOT use the “Get Material” function in the material editor.
Save Materials to File: Brings up a save file dialog box and saves the current material library to a file. If the current material library is empty then all scene materials will be added to the library before the file is saved.
Append Materials to Library: Adds the scene materials to the current material library.
Clear Library Materials: Removes all materials from the current material library.
All Library Materials to Scene: On a new layer a box is created for every material in the current material library. Each material is then applied to a box.

The following section is great for making thumbnails of an entire library.

Pick Camera: The camera to use for rendering.
Pick Object: Each material in the current material library will be applied to this object.
W: The width of the rendered image.
H: The height of the rendered image.
Render Now: Begins the rendering process. All images are saved as “material_name”.jpg. NOTE: During rendering the frame buffer might show an incorrect image, however the saved file should be correct.