Automating V-Ray material conversion - R8 bugs while R7 works correctly

I’ve been using a small script from @Nikolay that converts all materials in a file to V-Ray materials, which has been working fine for Archicad exports.

Recently, I’ve been trying to convert some .fbx tree files to .3dm files, so they can be rendered in V-Ray.

Rhino 7 seems to convert the materials correctly - matching the material properties from the imported Rhino material. I want to tweak the materials afterwards.

When I run the below script for Rhino 8, the material properties are no longer matching, with the opacity map lost for example.

Below the conversion script.

Side note: For some reason, when converting marterials with ‘leaf’ in the name, Vray adds a 2-sided material wrapper to them (which you can’t see in the dialog box). That’s why I rename materials leaf materials to TEMP. It allows me to work with them easily after.

import rhinoscriptsyntax as rs
import Rhino
import System
import rhVRay as vray

# Step 1: Rename all 'leaf' instances to 'TEMP' (case insensitive)
print("=== STEP 1: RENAMING LEAF MATERIALS ===")
doc = Rhino.RhinoDoc.ActiveDoc
name_mappings = {}  # Store temp_name -> original_name mapping

for material in doc.RenderMaterials:
    original_name = material.Name
    if 'leaf' in original_name.lower():
        # Replace 'leaf' with 'TEMP' (case insensitive)
        import re
        temp_name = re.sub(r'leaf', 'TEMP', original_name, flags=re.IGNORECASE)
        
        # Store the mapping using names
        name_mappings[temp_name] = original_name
        
        # Rename the material
        material.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Script)
        material.Name = temp_name
        material.EndChange()
        
        print("Renamed: {} -> {}".format(original_name, temp_name))

print("Renamed {} materials".format(len(name_mappings)))

# Step 2: Convert all materials to V-Ray
print("\n=== STEP 2: CONVERTING TO V-RAY ===")
vrayMtlId = System.Guid("68A07D39-9B12-4DCF-9007-E81EC233F0B7")
Rhino.RhinoApp.RunScript("_RenderMergeIdenticalMaterials *SameNameOnly=*Yes _Enter", True)

with vray.Scene.Transaction() as f:
    for m in [m for m in Rhino.RhinoDoc.ActiveDoc.RenderMaterials if m.TypeId != vrayMtlId]:
        Rhino.Render.Utilities.ChangeContentType(m, vrayMtlId, True)

print("Converted materials to V-Ray")

# Step 3: Rename TEMP materials back to original names
print("\n=== STEP 3: RESTORING ORIGINAL NAMES ===")
for material in doc.RenderMaterials:
    current_name = material.Name
    
    # Check if this material has TEMP in its name
    if 'TEMP' in current_name:
        # Find the matching original name
        for temp_name, original_name in name_mappings.items():
            if temp_name in current_name or current_name in temp_name:
                try:
                    material.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Script)
                    material.Name = original_name
                    material.EndChange()
                    
                    print("Restored: {} -> {}".format(current_name, original_name))
                    break
                except Exception as e:
                    print("Error restoring {}: {}".format(original_name, e))

# Step 4: Check results
print("\n=== STEP 4: CHECKING ALL MATERIAL TYPES ===")
with vray.Scene.Transaction() as f:
    vray_materials = vray.Scene.PluginsByType("MtlSingleBRDF", True)
    
    for material in vray_materials:
        try:
            brdf = material.Param("brdf").Value
            brdf_type = str(brdf).split('/')[-1] if '/' in str(brdf) else str(brdf)
            print("Material: {} -> BRDF: {}".format(material.Name, brdf_type))
        except:
            print("Material: {} -> Could not access BRDF".format(material.Name))

print("\nDone: All materials converted, names restored")

Anyone have any ideas what’s causing this?