Hello all
I was having tons of issues with layer visibility in detail view too.
I made a script that lets you turn off selected layers in the details views on the current layout… this has helped me save alot of time, especially after I have added model in new layer and those new elements show up in my old details.
In the code, you have the abilities to:
- select layer from a
rs.MultiListBox
- set visibility of the selected layer ON or OFF
- Apply to all details views on the current layout, or, apply to details you’ve selected
This is saving me time, so I thought I’ll share the code. It may not solve problems for everyone but maybe the code can be adapted and/or improved.
I’m also new to Rhinocommon. The script is using rs.command
so it’s not optimised, I’d like to know how to optimise it with Rhinocommon
I think this can also be done with a for loop to apply to multiple layouts, not just the current one.
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
def layerOffInDetails():
curView = sc.doc.Views.ActiveView
if type(curView) != Rhino.Display.RhinoPageView:
print 'The active view is not a layout view!'
return
#Get all layers in the current Rhino document
allLayers = rs.LayerNames()
### SINGLE LAYER INPUT - User is allowed to select one layer only ###
"""
#Get user selected layer
pickedLayer = rs.ListBox(allLayers, title = 'List of all layer')
#Get layer index from Rhino DocObjects Table
#sc.doc.layers => Rhino.DocObjects.Tables.LayerTable
layerTableIndex = sc.doc.Layers.FindByFullPath(pickedLayer, -1)
#Find document layer by index
layer = sc.doc.Layers.FindIndex(layerTableIndex)
"""
### MULTIPLE LAYER INPUT ###
pickedLayers = rs.MultiListBox(allLayers, title = 'List of all layer')
if not pickedLayers: return
### LAYER BY LAYER TABLE INDEX ###
layerTableIndexs = []
for pickedLayer in pickedLayers:
layerTableIndex = sc.doc.Layers.FindByFullPath(pickedLayer, -1)
layerTableIndexs.append(layerTableIndex)
### LAYER NAME BY LAYER TABLE INDEX
layers = []
for layerTableIndex in layerTableIndexs:
layer = sc.doc.Layers.FindIndex(layerTableIndex)
layers.append(layer)
### Visibility Setting ON/OFF ###
vis = rs.GetInteger('Set selected layer ON = 1 or OFF = 0', 0, 0, 1)
#if not vis: return
result = rs.GetString('Apply to all details or selected details', 'All', ['All', 'Selected'])
if result == 'All':
#Select all details from the current view, current should be a layout
rs.Command('_-SelDetail', echo = 0)
dvs = rs.SelectedObjects()
rs.UnselectAllObjects()
if result == 'Selected':
dvs = rs.GetObjects('Select details', rs.filter.detail)
rs.EnableRedraw(0)
#activate details one by one
for dv in dvs:
rs.SelectObject(dv)
rs.Command('_-Detail Enable', echo = 0)
#when detail is activated, set layer visibility
#layer.SetPerViewportVisible(sc.doc.Views.ActiveView.ActiveViewportID, vis)
### MULTIPLE LAYER INPUT ###
for layer in layers:
layer.SetPerViewportVisible(sc.doc.Views.ActiveView.ActiveViewportID, vis)
rs.Command('_-Detail EnablePage', echo = 0)
rs.UnselectAllObjects()
rs.EnableRedraw(1)
layerOffInDetails()