Bug Updating Layer Visibility Settings

This may be a resolved issue that has been resurrected when updating layer view state through the LayerTable. I converted the script discussed here into a compiled RhinoCommon plugin executed synchronously to demonstrate the issue.

layerStateTest.3dm (60.0 KB)

When Nested Layers Are Visible

Setting a nested layer visibility to off incorrectly sets the state to ‘half lite’:

  • Test 1 & 2: Root layers update correctly.
  • Test 3: Setting layer.IsVisible = false on nested layers incorrectly sets them to a ‘half lite’ state.
  • Test 4: You can click the ‘half lite’ icon and actually turn it off.
  • Test 5: Nested2 is correctly set to ‘half lite’ before this test. Turning it off programmatically does nothing.
  • Test 6: It’s more than a visual quirk. Nested2 should be off, but it acts like a ‘half lite’ layer. When its parent (Nested1A) is turned on, Nested2 also turns on.

2024.10.12.Rhino_ZrUclLMKfj

When Nested Layers Are Collapsed

this is using the same Test 3 as above, only with the Root layer collapsed

  1. Turn off Nested1A programmatically. The display updates correctly.
  2. Re-rendering the viewport behaves as expected
  3. Expanding Root reveals that Nested1A is on. Nested1A should be off and Nested2 should be ‘half lite’.
  4. Re-rendering the viewport spontaneously turns the off layers back on.

2024.10.12.Rhino_T9qpxv7vpc

The same applies to Python:

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc

def layerVisible (name, visibleP):
    layer = sc.doc.Layers.FindName(name)
    if not layer: return 
    layer.IsVisible = visibleP
    layer.CommitChanges()
    
def testSwitch():
    gn = Rhino.Input.Custom.GetNumber()
    gn.SetCommandPrompt("Test")
    gn.SetDefaultNumber(1)
    gn.SetLowerLimit(1, False)
    gn.SetUpperLimit(6, False)
    gn.AcceptNothing(True)
    
    gn.Get()
    res = gn.CommandResult()

    if res != Rhino.Commands.Result.Success: return
    testCase = gn.Number()
    if (testCase == 1): 
            layerVisible("Root", False)
    elif (testCase == 2):
            layerVisible("Root", True)                
    elif (testCase == 3): 
            layerVisible("Nested1A", False)
    elif (testCase == 4): 
            layerVisible("Nested1B", False)
    elif (testCase == 5):       
            layerVisible("Nested2", False)
    else:        
            layerVisible("Nested1A", True)
            
testSwitch()            

Hi @EricM,

Replace your layerVisible method with this:

def layerVisible (name, visibleP):
    layer = sc.doc.Layers.FindName(name)
    if not layer: return 
    layer.IsVisible = visibleP
    layer.SetPersistentVisibility(visibleP)
    layer.CommitChanges()

– Dale

1 Like