Is it possible to control the display on / off option using the API? [python]

image

Hello Please let me know if there is an API that can control the check / uncheck of Clipping Plane in Display mode as shown above. I would appreciate it if you could show me an example too.

Hi,

Yes, you should be able to do it like this (I modified another sample from RhinoCommon doc. online to turn off clippingplane display for selected displaymode):
https://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_Display_DisplayModeDescription_DisplayAttributes.htm


    import Rhino
    import scriptcontext

    # The following example demonstrates how to modify advanced display settings
    # using RhinoCommon. 

    def AdvancedDisplay():
        # Use the display attributes manager to build a list of display modes.
        # Note, these are copies of the originals...
        display_modes = Rhino.Display.DisplayModeDescription.GetDisplayModes()
        if not display_modes: return Rhino.Commands.Result.Failure

        # Construct an options picker so the user can pick which
        # display mode they want modified
        go = Rhino.Input.Custom.GetOption()
        go.SetCommandPrompt("Display mode to modify mesh thickness")
        opt_list = []
        for i, mode in enumerate(display_modes):
            english_name = mode.EnglishName
            english_name = english_name.translate(None, "_ -,.")
            opt_list.append( go.AddOption(english_name) )

        # Get the command option
        go.Get()
        if go.CommandResult()!=Rhino.Commands.Result.Success:
          return go.CommandResult();

        selected_index = go.Option().Index
        selected_description = None
        for i,option in enumerate(opt_list):
            if option==selected_index:
                selected_description = display_modes[i]
                break
        # Validate...
        if not selected_description: return Rhino.Commands.Result.Failure

        # Modify the desired display mode to turn off ClippingPlanes display
        selected_description.DisplayAttributes.ShowClippingPlanes = False
        # Use the display attributes manager to update the display mode.
        Rhino.Display.DisplayModeDescription.UpdateDisplayMode(selected_description)
        # Force the document to regenerate.
        scriptcontext.doc.Views.Redraw()
        return Rhino.Commands.Result.Success

    if __name__=="__main__":
        AdvancedDisplay()

@tr1004sm, @Jarek,

below is a simple toggle for the current vievport display mode, works in V6 only:

import Rhino
import scriptcontext

def DisplayModeToggleClippingPlanes():
    
    if Rhino.RhinoApp.ExeVersion < 6: return
    
    dmd = scriptcontext.doc.Views.ActiveView.ActiveViewport.DisplayMode
    state = dmd.DisplayAttributes.ShowClippingPlanes
    dmd.DisplayAttributes.ShowClippingPlanes = not state
    Rhino.Display.DisplayModeDescription.UpdateDisplayMode(dmd)
    scriptcontext.doc.Views.Redraw()
    
if __name__=="__main__":
    DisplayModeToggleClippingPlanes()

_
c.

1 Like