For Python, I found in the latest WIP that “layer.CommitChanges()” was missing to actually switch the layer light bulb state.
I tried to make the one-line fix in layers.py and the strangest thing happened, I altered layers.py file for the LayerVisible function, and moved the code position to insert a new addition, but when running code to debug, the debugger was pointing to the original code location and ignoring changes. Also the cursor was jumping to where the old code used to be and seemed to be executing code even thought text was where it was pointing.
Not being able to “fix” the lightbulb half-off issue, I simply copied code from Rhino6 WIP and added the missing activation line, then copied the necessary includes and functions not accessible to my program. Lastly, I removed the rs. in front of the LayerVisible commands in the program since I’m executing local functions.
Here is the complete code section added to my program. A bit ugly, but it works without altering the master code files.
#------------------------------------------------------
A replacement for layer visible half-lightbulb error
#------------------------------------------------------
import Rhino.DocObjects.Layer
import scriptcontext
import System.Guid
def LayerVisible(layer, visible=None, forcevisible_or_donotpersist=False):
""“Returns or changes the visible property of a layer.
Parameters:
layer (str): name of existing layer
visible (bool, optional): new visible state
forcevisible_or_donotpersist (bool, optional): if visible is True then turn parent layers on if True. If visible is False then do not persist if True
Returns:
bool: if visible is not specified, the current layer visibility
bool: if visible is specified, the previous layer visibility
”""
layer = __getlayer(layer, True)
rc = layer.IsVisible
if visible is not None:
layer.IsVisible = visible
if visible and forcevisible_or_donotpersist:
scriptcontext.doc.Layers.ForceLayerVisible(layer.Id)
if not visible and not forcevisible_or_donotpersist:
layer.SetPersistentVisibility(visible)
layer.CommitChanges()
scriptcontext.doc.Views.Redraw()
return rc
def __getlayer(name_or_id, raise_if_missing):
if not name_or_id: raise TypeError(“Parameter must be a string or Guid”)
id = coerceguid(name_or_id)
if id: name_or_id = id
else:
layer = scriptcontext.doc.Layers.FindByFullPath(name_or_id, True)
if layer>=0: return scriptcontext.doc.Layers[layer]
layer = scriptcontext.doc.Layers.Find(name_or_id, True)
if layer>=0: return scriptcontext.doc.Layers[layer]
if raise_if_missing: raise ValueError("%s does not exist in LayerTable" % name_or_id)
def coerceguid(id, raise_exception=False):
if type(id) is System.Guid: return id
if type(id) is str and len(id)>30:
try:
id = System.Guid(id)
return id
except:
pass
if (type(id) is list or type(id) is tuple) and len(id)==1:
return coerceguid(id[0], raise_exception)
if type(id) is Rhino.DocObjects.ObjRef: return id.ObjectId
if isinstance(id,Rhino.DocObjects.RhinoObject): return id.Id
if raise_exception: raise TypeError(“Parameter must be a Guid or string representing a Guid”)
#-----------------------------------
I assume this will be corrected for Rhino6, but there are a lot of Rhino5 users stuck with this problem.
Regards, Ray
H