D5 only recognizes Rhino materials if they are created manually

I’m working on a project from a rhino file . Everything in this project is very neatly organized in layers so that every material of every wall , object , building etc. is sorted in the corresponding layer .
As a result we have hundreds of layers . Through a simple grasshopper file , I can automatically assign a material that matches each layer’s name and color . They appear just fine in the rhino render , with their specific colors etc.
I can also do that 3auto material creation" with a script assigned to a command .

HOWEVER once I import those in D5 , D5 is incapable of recognizing those materials and instead applies the “defaultmaterial” to all of them . This happened whether the objects were inside of blocks or not .

If instead I create a material for each layer by copying the name of the layer , clicking on the empty material node and pasting the layer name to create a new material , now D5 recognizes them as new distinct materials . What gives ? I don’t see any secret material ID which could cause rhino to see them as materials while D5 can’t recognize them .

Hi @seb.eble

When a material is generated automatically via a script or a Grasshopper file, it may not be fully defined within Rhino’s material library. These materials include only basic attributes like a name and color, while lacking key properties that D5’s import process requires:

  • Such as a material ID, shader type, or texture slots. In many cases, Rhino creates a temporary material that functions solely within its own rendering environment and may not translate properly when exported to D5
1 Like

Hi @seb.eble ,

What if you tried to use the command “SynchronizeRenderColors” in Rhino?
That way, Rhino automatically assign materials to every layer (materials get same color as layers)

1 Like

That is a useful command. Only drawbacks are that it makes all materials called Custom, Custom (1) Custom (2), etc, So no clear idea as to which layer they below to.
An alternative Rhino script (below) written by a friend recolors all the layer (maybe not ideal) and adds a material based on the layer color and layer name. I may try rewriting it to preserve the layer color (important if you have specific standards), but keep the material named after the layer name.

’ Assign unique layer colors and create/match materials to each layer
Option Explicit

Call Main()
Sub Main()
Dim arrLayers, i, strLayer, clr, matIndex, matName, arrObjects

arrLayers = Rhino.LayerNames()
If IsNull(arrLayers) Then
	Rhino.Print "No layers found."
	Exit Sub
End If

Rhino.EnableRedraw False
For i = 0 To UBound(arrLayers)
	strLayer = arrLayers(i)

	' generate a hue around the color wheel (golden-step)
	clr = HSVtoRGB((i * 137) Mod 360, 0.75, 0.95)

	' set the display color of the layer
	Call Rhino.LayerColor(strLayer, clr)

	' get existing material index for the layer (-1 means none)
	matIndex = Rhino.LayerMaterialIndex(strLayer)
	If matIndex = -1 Then
		matIndex = Rhino.AddMaterialToLayer(strLayer) ' adds material and assigns it to the layer
	End If

	If Not IsNull(matIndex) Then
		matName = strLayer
		Call Rhino.MaterialName(matIndex, matName)
		Call Rhino.MaterialColor(matIndex, clr)
	Else
		Rhino.Print "Failed to add/get material for layer: " & strLayer
	End If

	' --- OPTIONAL: force all objects on the layer to use the layer material ---
	' Uncomment the next lines if you want objects on the layer to be set to "Material from layer"
	' arrObjects = Rhino.ObjectsByLayer(strLayer)
	' If IsArray(arrObjects) Then
	'     Call Rhino.ObjectMaterialSource(arrObjects, 0) ' 0 = material from layer
	' End If
	' -------------------------------------------------------------------------

Next
Rhino.EnableRedraw True
Rhino.Print "Done: layer colors and materials updated."

End Sub

'-----------------------------
’ HSV to RGB helper (h:0-360, s:0-1, v:0-1) → returns VB RGB long
Function HSVtoRGB(h, s, v)
Dim r, g, b, i, f, p, q, t
h = h Mod 360
If s = 0 Then
r = v: g = v: b = v
Else
i = Int(h / 60)
f = (h / 60) - Int(h / 60)
p = v * (1 - s)
q = v * (1 - f * s)
t = v * (1 - (1 - f) * s)
Select Case i
Case 0: r = v: g = t: b = p
Case 1: r = q: g = v: b = p
Case 2: r = p: g = v: b = t
Case 3: r = p: g = q: b = v
Case 4: r = t: g = p: b = v
Case 5: r = v: g = p: b = q
Case Else: r = v: g = v: b = v
End Select
End If
HSVtoRGB = RGB(CInt(r * 255), CInt(g * 255), CInt(b * 255))
End Function