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)
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"
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)
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)
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)
This script is super helpful! I have almost no scripting knowledge but I have successfully adapted it so it changes to Shaded instead, however I am trying to do the same for Technical but I am getting an ‘object has no attribute’ error… I am assuming that the word Technical is wrong in itself? Would you be able to show me how to get it to work?