Loading .rmtl files and assigning materials to objects


I am looking for any hint to the following two-step task using PythonScript :

  1. loading an .rmtl file
    (as e.g. rs.Command("_RenderLoadMaterialFromFile MyMaterial.rmtl"))
  2. assigning this material to an object
    (as e.g. rs.ObjectMaterialIndex(MyObject, IndexValue)

Unfortunately I am unable to determine the proper value for IndexValue;
How is it possible to manage the material table in order to know it ?


Hi @cyl, if you do not want to mess with material indices at all you could use

_RenderAssignMaterialToObjects "YourMaterialName"

in rs.Command().however this requires that you select the objects to which the material is assigned. To go the python route, you can find out all material names and indices from the material table. Something like below might help:

import scriptcontext 

def FindMatIndexByMatName():
    mat_table = scriptcontext.doc.Materials
    index = mat_table.Find("White Matte", True)
    if index >= 0:
        print "MaterialIndex: {}".format(index)
        print "Not found"

if __name__=="__main__":


Many thanks !
The proposed function allow to read the materials table (and help me a lot in managing materials).