Python - Create Rhino/VRay materials from list of textures


I have a collection of 1000+ different PBR textures in different folders and have been trying to write a Python script to sort the different textures by name (e.g. Asphalt01, Asphalt02… Wood09) and by types (e.g. diffuse, bump, roughness, displacement, etc.), which are then paired into a dictionary with texture names as keys and texture types as values. The file locations have also been mapped to a list.
This has all worked fine, however now I need to assign the different textures/maps to Rhino materials (and hopefully also VRay materials) and save these as .rtml/.vrmat-files, but I don’t know how to create these materials and save them.

This is what I need help with:

  def create_materials(mat_dict, fileroot):

    for name in mat_dict:
        for name_tex in mat_dict[name]:
            name_tex_lower = name_tex.lower()
            name_tex_split = re.split("[_.]", name_tex_lower)

            if "dif" or "col" in name_tex_split:
                #Assign diffuse map to material
            elif "dis" in name_tex_split:
                #Assign displacement map to material
            elif "rou" in name_tex_split:
                #Assign rougness map to material
            elif "nor" or "bum" in name_tex_split:
                #Assign normal/bump map to material
            elif "met" in name_tex_split:
                #Assign metal map to material
            elif "spe" in name_tex_split:
                #Assign specular map to material
            elif "opa" in name_tex_split:
                #Assign opacity map to material

I imagine the Rhino materials can be created using the following code, but changed to work with the above. However I would like to save the created materials, which I have no idea how to do:

    #Create Rhino material
    list_material = Rhino.DocObjects.Material()
    list_material.Name = "var_name"
    #Create basic render material
    list_render_material = Rhino.Render.RenderMaterial.CreateBasicMaterial(list_material)
    #Add basic material to Rhino document

The script has been written for and within Rhino 6, but I’ll upgrade to Rhino 7 soon. I imagine the method for creating PBR materials in Rhino 7 is different from creating basic materials in Rhino 6, so any help towards writing the script towards Rhino 7 is also much appreciated. :wink:


EDIT: Uploaded the python file to the original post (3.8 KB)

1 Like

Just zip it, and upload the .zip.

did you ever get the script to work?