Set different materials for different layers

Hello everyone,

I would like to know if there is any way that I could set different materials for all layers I have so each layer could have its own exclusive material. I tried to search but could find nothing like this.

Thanks!

Hello - there is no automatic way in plain Rhino, no…

-Pascal

Is it possible for another version? Or maybe even a script?

It would be nice =)

Some info about your typical layer structure would be good here, also what is your use case?

There are many rules as to what layer gets what material, one way would be to set layer material by layer color:

import Rhino
import scriptcontext as sc

def createAndSetLayerMaterialByLayerColor():
    
    for layer in sc.doc.Layers:
        material = Rhino.DocObjects.Material()
        material.Default()
        material.DiffuseColor = layer.Color
        
        layer.RenderMaterial = material.RenderMaterial
        
    sc.doc.Views.Redraw()
    
if __name__ == "__main__":
    createAndSetLayerMaterialByLayerColor()

but is there anyway that I can set automatically to all layers different colors ?

try this:

import Rhino
import scriptcontext as sc
import random
import System.Drawing as draw

def createAndSetLayerMaterialRandomColor():
    
    #random seed
    seed = 123456
    random.seed(seed)
    
    for layer in sc.doc.Layers:
        
        # create random color
        randColor = draw.Color.FromArgb(255, random.randint(0,255), random.randint(0,255), random.randint(0,255))
        
        # create new material and set it to the random color
        material = Rhino.DocObjects.Material()
        material.Default()
        material.DiffuseColor = randColor
        
        # set material as layer material
        layer.RenderMaterial = material.RenderMaterial
        
        # if you want layer and layermaterial to have the same color
        # uncomment the next line
        # layer.Color = randColor
        
    sc.doc.Views.Redraw()
    
if __name__ == "__main__":
    createAndSetLayerMaterialRandomColor()

wow! hey man sorry for seeing this late, but the code is AWESOME! thanks a lot man! If I can help you anyway just shout me out!

Appreciate!