Hello,
I tried using the Layer.SetPerViewportVisible method today, and i just can’t get it to work, is there a code sample around i can refer to?
Layer.SetPerVieportVisible(System.Guid.Empty, False) works like expected, but neither detailViewObject.Id nor detailViewObject.Viewport.Id seem to be doing anything, and no error is returned.
import Rhino
import scriptcontext as sc
def Test():
view = sc.doc.Views.ActiveView
if view is None:
return
if type(view) is Rhino.Display.RhinoPageView:
index = sc.doc.Layers.FindByFullPath("Layer 01", -1)
if (index >= 0 and index < sc.doc.Layers.Count and index != sc.doc.Layers.CurrentLayerIndex):
layer = sc.doc.Layers[index]
if layer and layer.IsVisible:
layer.SetPerViewportVisible(view.ActiveViewportID, False)
view.Redraw()
Test()
My specific use case is a “one layer on” for details where my files have between around 10 and well over a 100 pageviews, all with 1 detailview on them and i want to have only a group of layers to be visible per detail. The grouping is solved via naming convention (Detail 001 should only display Layers whose names start with 001 for example).
I got it to work now, I guess it was more of a looping mistake:
i iterated over all layers and by layer went into a nested for loop, checking all pageviews which did work but wierdly only for the last pageview in the rhinodoc.
working code now iterates over pageviews and by pageview over all layers, posting my solution here if somebody tries to do something similar in the future:
def test2():
for pageView in sc.doc.Views.GetPageViews():
for detailView in pageView.GetDetailViews():
for layer in sc.doc.Layers:
# check for deleted layer
if not layer.HasName:
continue
# use layer structure specific logic here
if layer.Name.Split()[0] in detailView.Name:
layer.SetPerViewportVisible(detailView.Id, True)
else:
layer.SetPerViewportVisible(detailView.Id, False)
if __name__ == "__main__":
test2()