Changed LayerVisible(), to use layer.SetPersistentVisibility(False).
Without this line layers that have been switched off with LayerVisible(l,
visible=False), behave strangely when they have parent layers. If the
parent layer is switched on and the child layer is switched off via the
function, it will not be fully off as in pushing the light bulb in the
layer editor UI. The child layer is in the state that it would have, when the parent
layer would be switched of (the half light bulb). This behavior is in
contrast to the behavior achieved with the UI. Furthermore, when a child
layer is in theis weird hidden state and any layer is switched to locked
with the button in the layer manager, the hidden child layer switches back
on.
LayerLocked(), added line layer.SetPersistentLocking(True) for it to work properly. Without this line when locking a layer with the function LayerLocked(ln, locked=True), goes into the same lock state as if it would be unlocked but have a locked parent layer (the half lock symbol). This is in contrast to how the Rhino UI behaves. It is a similar problem  that I encountered with LayerVisible(). For LayerVisible() the persistent function had to be called with False, for LayerLocked() it had to be called with true.