Python/Rhinoscriptsyntax layer/sublayer-related "issues"

Issue #1:

With a new blank file containing just one layer “Default”…

In vb Rhinoscript, run the following code:

Option Explicit
Call TestAddSubLayer()
Sub TestAddSubLayer()
    Call Rhino.AddLayer("Default::NewLayer")
End Sub

The layer NewLayer is added as a sublayer of Default.

Now, do the same thing with Python rhinoscriptsyntax (start with a new file):

import rhinoscriptsyntax as rs
rs.AddLayer("Default::NewLayer")

A new top-level layer is added with the name Default::NewLayer… Not how it’s supposed to work IMO…

Issue #2:

In the file created in the first step above - with a Top layer “Default” and a sublayer “NewLayer” - put one object (anything) on the sublayer “NewLayer”

In vb rhinoscript run the following and choose the object:

Option Explicit
Call TestGetObjectLayer()
Sub TestGetObjectLayer()
    Dim obj : obj = Rhino.GetObject()
    Call Rhino.Print(Rhino.ObjectLayer(obj))
End Sub

Returns: Default::NewLayer

Now, run the Python equivalent and do the same:

import rhinoscriptsyntax as rs
obj = rs.GetObject()
print rs.ObjectLayer(obj)

Returns:  NewLayer

These sublayer issues are driving me nuts - making it very hard to script layer operations with sublayers in python rhinoscript syntax…

IMO, all rhinoscriptsyntax methods need to return the full layer path. Also, for both vb and python, optional arguments to return the layer ID instead of the name would be good.

Thanks,
–Mitch

I’ll add these to the big Python pile…

Fixed the 1st issue but the 2nd one was already addressed.

Thanks Alain!! Cheers, --Mitch

I’m seeing an issue with turning off sublayers with Python.

Try this:

Make a few layers, then create sublayers. Make them a few levels deep like this:

Now, run this Rhinoscript and notice how the sublayers shut off:

Option Explicit

Sub TurnSubLayersOff()
    Dim arrLayers
    Dim strLayer
    Dim strParent
    
    arrlayers = Rhino.LayerNames()
    If IsArray(arrLayers) Then
        For Each strLayer In arrLayers
            strParent = Rhino.ParentLayer(strLayer)
            If Not IsNull(strParent) Then
                If Rhino.IsLayerChildOf(strParent, strLayer) Then
                    If Rhino.IsLayerCurrent(strLayer) = False Then
                        Call Rhino.LayerVisible(strLayer, False)
                    End If
                End If
            End If
        Next
    End If
End Sub

TurnSubLayersOff

Now, try my Python code (I’m assuming my code is as effective as it could be):

import rhinoscriptsyntax as rs

def TurnSubLayersOff():
    layers = rs.LayerNames()
    if layers:
        for layer in layers:
            parent = rs.ParentLayer(layer)
            if parent:
                if rs.IsLayerChildOf(parent, layer):
                    if not rs.IsLayerCurrent(layer):
                        rs.LayerVisible(layer, False)

if __name__ == "__main__":     
    TurnSubLayersOff()

Notice the different results. The Rhinoscript version works, and the Python version doesn’t do two things. First, it fails to update the layer list (I have a docked layer pane), and second, it fails to completely shut off the layers. I can add a Redraw to the Python script to make sure the layer pane is up-to-date, but the layer pane is still showing 1/2 bulbs on:

Thanks,

Dan

I had also thought this was fixed… I think it’s only a problem with python’s managing the lightbulb display in the layer box, the sublayers actually have been turned off (put some objects on them to see)…

–Mitch

Yes, I see that now. Adding a Redraw helps, but it doesn’t quite emulate what Rhinoscript is doing. Still getting 1/2 bulbs. But you are right, the sub-layers are turning off.

Thanks,

Dan

Hi Dan and Mitch,

This thread was about issues related to layer full names and those have been fixed although they’re not in Rhino 5 yet. I’ll have a look at the visibility issues as well.

Thanks for reporting.
Alain