Flat Shade via c# or python?

Hello

How to control Flat Shade in Grasshopper using c# or python?

Rhino.Render.RenderSettings.FlatShade might do it for you.

I tried it but didn’t work

import Rhino

def set_viewport_flat_shade(flat_shade_enabled):

    doc = Rhino.RhinoDoc.ActiveDoc
    view = doc.Views.ActiveView
    if not view:
        return

    if doc:
        doc.RenderSettings.FlatShade 
    view.Redraw()


set_viewport_flat_shade(enable)

It’s a property, so you need to assign a boolean, something like:

doc.RenderSettings.FlatShade = True

Actually, for render settings to properly change you need to to:

# doc expected to be a RhinoDoc
rs = doc.RenderSettings
rs.FlatShade = True
doc.RenderSettings = rs

edit: note that if you wan’t to change this for a display mode in a viewport you probably want to play with https://developer.rhino3d.com/api/rhinocommon/rhino.display.displaypipelineattributes/frontflatshaded

I try this, but don’t work,

import Rhino

doc = Rhino.RhinoDoc.ActiveDoc
rs = doc.RenderSettings
rs.FlatShade = True
doc.RenderSettings = rs

doc.Views.Redraw()

and FrontFlatShaded is not available for Rhino 7

Right, you didn’t specify Rhino version so I assumed Rhino 8. You probably should try DisplayPipelineAttributes.ShadingEnabled Property then.

Get the display mode description for the view you want to manipulate and make the necessary change. Check the example at DisplayModeDescription.DisplayAttributes Property .

Thanks

ShadingEnabled: Draw shaded meshes and surfaces

FlatShade: Gets or sets a value indicating whether to render using flat shading.

I use run command to enable disable flatshade:

import Rhino as rh
import Grasshopper as gh

if run:
     gh.Plugin.GH_PluginUtil.SendKeyCodeToRhino("_FlatShade _Enter")
     rh.RhinoApp.SetCommandPrompt("")
rh.RhinoDoc.ActiveDoc.Views.Redraw()

It is not the best way but it works