Hi,
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)
name_tex_split.pop(0)
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.SetBitmapTexture(var_filepath)
list_material.SetBumpTexture(var_filepath)
list_material.Name = "var_name"
#Create basic render material
list_render_material = Rhino.Render.RenderMaterial.CreateBasicMaterial(list_material)
#Add basic material to Rhino document
sc.doc.RenderMaterials.Add(list_render_material)
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. 
I can’t seem to upload the python file I’ve written, and I’ve left out some of the less important things from the script, but if you need it, please let me know how to upload the python file.
Thanks!
3 posts - 2 participants