Modify material names in RhinoScript

I used “Rhino.MaterialName” method in RhinoScript to modify the material names. Those changes shows up in layer panel, but not in material editor. And when I save and reopen the file. All changes are gone.

Here is my code:

Sub AddPrefixToAllMaterials()
	Dim arrMaterials, strMaterial, intIndex, strNewName, strPrefix

	arrMaterials = Rhino.MaterialIds
	strPrefix = Rhino.GetString("Prefix to add")

	If IsArray(arrMaterials) Then

		For Each strMaterial In arrMaterials
			intIndex = Rhino.MaterialIndex(strMaterial)
			strNewName = strPrefix + Rhino.MaterialName(intIndex)
			If IsNull(strPrefix) Then
				Rhino.Print("NewName is Null")						
				Rhino.MaterialName intIndex, strNewName
			End If
	End If
End Sub

Can somebody help? Thank you!

It looks like a problem only exist in Rhino6. When I tried the same code in Rhino 7, it works fine. However, I have to use rhino 6 for my current project. Can anyone shed some light on this issue?

I don’t know RhinoScrip, but you can try this rhinopython code.

import scriptcontext as sc
import rhinoscriptsyntax as rs

rdk = rs.GetPlugInObject("Renderer Development Kit")
con = rdk.ContentList("material")
for i in xrange(len(con)):
    rdk.ContentInstanceName(con[i],"A" + str(i))