3dsmax : Name An Object From Material Name

This question came a few days ago via a comment. Is it possible to name an object by simply checking the material, and assign that name to the object? Answer is yes, and here is a script that will accomplish this easy task.

A selected object’s material name can be accessed with :

Assigning a name to an object goes like this :
$.name = “MyNewName”

And for a unique name you can use this one :
$.name = uniqueName “MyNewName”

If you’ve got more than one object selected, you can do something like this :

sel = selection as array
count = 1
undo on
    if sel.count > 0 then
      while count <= sel.count do
        select sel[count]
        count += 1
        $.name = uniqueName ($.material.name as String)

This will get the material name, and assign it to the object. Plus, it adds an auto incremented number at the end of each name. You can simply delete “uniqueName”, if you do not want this number. Objects can have same names, 3dsmax will not mind.

There is no error caching in this script. If you select an object that is not a member of the mesh class (like lights, cameras, helpers, etc), you might encounter errors.