Removing duplicate material names in layer panel

when I run this script the actual material remains unchanged in the edit panel.

	Dim arrMat
arrMat = rhino.MaterialIndices

Dim x
x = 0
For  x=0 To ubound(arrmat) - 1
	Dim matName
	matName = rhino.MaterialName(arrMat(x))
	Dim arrMatName
	arrMatName = rhino.MaterialsByName(matName)
	If isArray(arrMatName) Then
		rhino.MaterialName arrMat(x), matName & x		
	End If


Edit - OK, I am seeing the same thing here…
Below is my slightly restructured version, but the basic principle is the same, the material name updates in the layer box, but not in the material panel, and if you save and reopen the file, the changes are also removed from the layer box… Don’t have time to investigate further right now…

Call MakeUniqueLayerMatNames()
Sub MakeUniqueLayerMatNames()
    Dim arrMatIndices, i, strMatName, arrMatName
    arrMatIndices = Rhino.MaterialIndices

    For  i=0 To ubound(arrMatIndices)
        strMatName = Rhino.MaterialName(arrMatIndices(i))
        arrMatName = Rhino.MaterialsByName(strMatName)
        If IsArray(arrMatName) Then
            Rhino.MaterialName i, strMatName & "-" & Cstr(i)    
        End If
End Sub


Thanks for the code Mitch,

My file only updated 1 material name in the edit panel (New Material 002-1) the others remained unchanged.

File attached: material names.3dm (46.9 KB)


@dale is this fixable ?


Had the same problem many times in the past. I think RS methods are not completely in sync with RDK materials. Hope it will get all solved at some point. See more info in this thread: RS: Rhino.MaterialName problem