Change all detail view display modes

I’m working on a drawing that has about 9 sheets that each have a shaded detail viewport or two. While annotating I’d like to be able to make all viewports wireframe display mode to speed things up. My python code is not working, I can change the typical 4 views and the layouts to wireframe, but I can’t seem to figure out how to change the detail viewports display mode. Any thoughts?

import rhinoscriptsyntax as rs
import Rhino

def RunCommand( is_interactive ):

    views = rs.ViewNames(return_names=False, view_type=1)
    for view in views:
        if view == rs.IsLayout(view):
            print view
            details = Rhino.DetailNames(view, False)
            for detail in details:
                rs.ViewDisplayMode(detail, 'Wireframe')
    rs.Redraw()

if( __name__=="__main__" ):
    RunCommand(True)

Hi Jake,

I think you will need some RhinoCommon to do this:

import Rhino
import scriptcontext as sc

def SetDetailsToWireframe():
    display_mode = Rhino.Display.DisplayModeDescription.FindByName("Wireframe")
    if display_mode:
        page_views = sc.doc.Views.GetPageViews()
        for page_view in page_views:
            details = page_view.GetDetailViews()
            for detail in details:
                if detail.Viewport.DisplayMode.Id != display_mode.Id:
                    detail.Viewport.DisplayMode = display_mode
                    detail.CommitViewportChanges()
            page_view.Redraw()

– Dale

Dale,
I’m not very familiar with rhinocommon, so I’m working my way through this. I added a few prints for debugging and found that ‘details’ was not always a list so added an ‘if’ statement and was able to make it down to the last ‘for’ statement. Any reason I’m getting the error below?

import Rhino
import scriptcontext as sc


def RunCommand( is_interactive ):
    display_mode = Rhino.Display.DisplayModeDescription.FindByName("Wireframe")
    print display_mode
    if display_mode:
        page_views = sc.doc.Views.GetPageViews()
        print page_views
        for page_view in page_views:
            details = page_view.GetDetailViews()
            if isinstance(details,list):
                print "its a list"
            else:
                details = [details]
            for detail in details:
                if detail.Viewport.DisplayMode.Id != display_mode.Id:
                    detail.Viewport.DisplayMode = display_mode
                    detail.CommitViewportChanges()
            page_view.Redraw()
if( __name__=="__main__" ):
    RunCommand(True)

Message: 'Array[DetailViewObject]' object has no attribute 'Viewport'

Traceback:
line 18, in RunCommand, "C:\Users\jcp\Documents\Working Myfiles\Rhino\Python\AllVPortWireframe_dale.py"
line 23, in <module>, "C:\Users\jcp\Documents\Working Myfiles\Rhino\Python\AllVPortWireframe_dale.py"

Hi Jake,

My prior example didn’t have much error checking, such as verifying a page view had details. This one is a little better.

import Rhino
import scriptcontext as sc

def SetDetailsToWireframe(debug):
    # Find the wireframe display mode
    display_mode = Rhino.Display.DisplayModeDescription.FindByName("Wireframe")
    if display_mode:
        DebugPrint(display_mode, debug)
        # Get all of the document's page views
        page_views = sc.doc.Views.GetPageViews()
        if page_views:
            # Process each page view
            for page_view in page_views:
                DebugPrint(page_view, debug)
                # Get all of the page view's details
                details = page_view.GetDetailViews()
                if details:
                    # Process each page view detail
                    for detail in details:
                        DebugPrint(detail, debug)
                        # If the detail's display mode is not wireframe...
                        if detail.Viewport.DisplayMode.Id != display_mode.Id:
                            # ...set it to wireframe.
                            detail.Viewport.DisplayMode = display_mode
                            detail.CommitViewportChanges()
                    # Redraw the page
                    page_view.Redraw()

def DebugPrint(object, debug):
    if object and debug:
        print object

SetDetailsToWireframe(True)
1 Like

Dale, thanks for the updated code, it worked great. I couldn’t help but add a little improvement (with the help of @NavArch) to make it a bit more robust by selecting a display mode from a listbox.

import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs

def SetDetailsToWireframe(debug):
    modes = rs.ViewDisplayModes()
    setmode = rs.ListBox(modes, "Select mode")
    # Find the wireframe display mode
    display_mode = Rhino.Display.DisplayModeDescription.FindByName(setmode)
    if display_mode:
        DebugPrint(display_mode, debug)
        # Get all of the document's page views
        page_views = sc.doc.Views.GetPageViews()
        if page_views:
            # Process each page view
            for page_view in page_views:
                DebugPrint(page_view, debug)
                # Get all of the page view's details
                details = page_view.GetDetailViews()
                if details:
                    # Process each page view detail
                    for detail in details:
                        DebugPrint(detail, debug)
                        # If the detail's display mode is not wireframe...
                        if detail.Viewport.DisplayMode.Id != display_mode.Id:
                            # ...set it to wireframe.
                            detail.Viewport.DisplayMode = display_mode
                            detail.CommitViewportChanges()
                    # Redraw the page
                    page_view.Redraw()

def DebugPrint(object, debug):
    if object and debug:
        print object

SetDetailsToWireframe(True)

This is very helpful.

I’m not familiar with python… could someone please explain a way to change the script so that it only affects the current layout?

I often produce drawings with over 10 viewports on one page.

Thanks!

@JVN, I’m still not very good at scripting, but I’ve learned to cobble things together with guidance from forums and references. I think if you look at https://developer.rhino3d.com/samples/rhinocommon/determine-active-viewport/ you may be able to figure out how to make the changes only to the current layout.

Hi @JVN,

How about this?

import Rhino
import scriptcontext as sc

def SetActiveLayoutDetailsToWireframe():
    view = sc.doc.Views.ActiveView
    if isinstance(view, Rhino.Display.RhinoPageView):
        wireframe_id = Rhino.Display.DisplayModeDescription.WireframeId
        wireframe_mode = Rhino.Display.DisplayModeDescription.GetDisplayMode(wireframe_id)
        for detail in view.GetDetailViews():
            if detail.Viewport.DisplayMode.Id != wireframe_mode.Id:
                detail.Viewport.DisplayMode = wireframe_mode
                detail.CommitViewportChanges()
        view.Redraw()

SetActiveLayoutDetailsToWireframe()

– Dale

This is great, thank you. I’m just trying to get that list box to pop up, so I can choose the display mode.

Here is our script that generates a list box of view modes. You’ll have to mash this up with the script @dale posted.

import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs

def SetDetailsToWireframe(debug):
    modes = rs.ViewDisplayModes()
    setmode = rs.ListBox(modes, "Select mode")
    # Find the wireframe display mode
    display_mode = Rhino.Display.DisplayModeDescription.FindByName(setmode)
    if display_mode:
        DebugPrint(display_mode, debug)
        # Get all of the document's page views
        page_views = sc.doc.Views.GetPageViews()
        if page_views:
            # Process each page view
            for page_view in page_views:
                DebugPrint(page_view, debug)
                # Get all of the page view's details
                details = page_view.GetDetailViews()
                if details:
                    # Process each page view detail
                    for detail in details:
                        DebugPrint(detail, debug)
                        # If the detail's display mode is not wireframe...
                        if detail.Viewport.DisplayMode.Id != display_mode.Id:
                            # ...set it to wireframe.
                            detail.Viewport.DisplayMode = display_mode
                            detail.CommitViewportChanges()
                    # Redraw the page
                    page_view.Redraw()

def DebugPrint(object, debug):
    if object and debug:
        print object

SetDetailsToWireframe(True)