How to set display colours to material colours

Hey there,

Sorry to reactivate this topic years later.
I would like to create Materials for objects from their Display Color, and not from their Layer Color.
The idea is to get the same colors, on both the Shaded View and in the Rendered View. Very basic stuff.
Is there some command to do that ?
Or should I do some scripting ?

@dale you might have an idea maybe.

Thanks a lot in advance and best regards,

Loïc

1 Like

Just found this as well, which works fine. I post it for others

Thanks for the help, it’s solved.

Hi,
There you go

import Rhino
import scriptcontext
import System
def CreateMaterialFromDisplayColor():
    rhino_objects = scriptcontext.doc.Objects
    for obj in rhino_objects:
        try:
            display_color = obj.Attributes.DrawColor(scriptcontext.doc)
            material_index = scriptcontext.doc.Materials.Add()
            material = scriptcontext.doc.Materials[material_index]
            material.DiffuseColor = System.Drawing.Color.FromArgb(display_color.A, display_color.R, display_color.G, display_color.B)
            material.CommitChanges()
            obj.Attributes.MaterialIndex = material_index
            obj.Attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject
            obj.CommitChanges()
        except Exception as e:
            print("An error occurred while processing object {obj.Id}: {e}")
CreateMaterialFromDisplayColor()

Hope this helps

-Farouk

1 Like

Hi,
Thanks, thank you, it helped me a lot

1 Like