R8: how to turn off a model space layer locally?

Hello!
Since R8 the model space layers have this second, local visibility icon (praise you for that!).
I wanted to ask how to set that in Python.

Last year I wrote a script that turns off all the layers of the selected objects (because there’s only OneLayerOff, which is a bit meager).

HideLayers_cmd.py (4.0 KB)

It worked fine in R7, and I’m trying to make it fit for R8.
The script detects the type of the viewport (“StandardModelingViewport” or “DetailViewport”), and turns off the layer’s local or global visibility given by a command option.
It works in a detail viewport, but the method

layer.SetPerViewportVisible(view.ActiveViewportID, False)

does not seem to work for model space viewports. Is there another way to access this new “local” layer visibility, or is this a bug, or something unexposed yet?

Thanks!

Hi @Eugen,

Use the Layer.ModelIsVisible property.

import Rhino
import scriptcontext as sc

def layers_modelview_off():
    rc, selected = Rhino.UI.Dialogs.ShowSelectMultipleLayersDialog(None, "Select layers to turn model views off:", False)
    if not rc: return
    
    for index in selected:
        layer = sc.doc.Layers[index]
        if layer and layer.ModelIsVisible:
            new_layer = Rhino.DocObjects.Layer()
            new_layer.CopyAttributesFrom(layer)
            new_layer.ModelIsVisible = False
            sc.doc.Layers.Modify(new_layer, layer.Id, True)

if __name__ == "__main__":
    layers_modelview_off()

– Dale

1 Like

Thanks, Dale, that works!

Updated script:
HideLayers_cmd.py (4.4 KB)

In R8, it works for all ‘spaces’ - model, layout, detail, and asks if the layers should be hidden globally or locally (In R7, when in model space, the layers are turned off immediately).

By the way: the new Script Editor in R8 became pretty cool, congratulations!