Bug - Add child layer


I am trying to add a new layer and child layers.
Seems that child layers are not really child.
GH definition is enclosed.
AddChildLayer_Bug.gh (3.1 KB)


Look at this:

AddChildLayer_Bug_RE.gh (7.2 KB)

I added a “lookup_parent” to the code ensuring that the new parent aquired a valid id. Hopefully they have fixed things like this in R6. Annoying.

// Rolf

Thanks, Rolf!

Maybe @stevebaer can look at this to fix it in the following release.

That layer information that is added to the document is copied and I’m a little hesitant to just tweak the layer that you provide as input to have an updated Id (and probably Index). Just use the index returned from the Add function to get at the Layer maintained by the document. This is less effort than using Find functions.

  Private Sub RunScript(ByVal lname As String, ByVal n As Integer, ByRef A As Object) 
    Dim mlaymain As New Layer()
    mlaymain.Name = lname
    Dim layindmain As Int32 = RhinoDocument.Layers.Add(mlaymain)
    `the following line is all I added
    mlaymain = RhinoDocument.Layers(layindmain)

    Dim i As int32 = 0
    For i = 0 To n - 1
      Dim ml As Int32 = i + 1
      Dim clname As String = "Level" & ml.tostring
      Dim mlay As New layer()
      mlay.Name = clname
      mlay.ParentLayerId = mlaymain.Id
      mlay.Color = Drawing.Color.Red
      Dim layind As Int32 = RhinoDocument.Layers.Add(mlay)
  End Sub 

Ah, I recall trying to use “Layers[layindmain]” but got compiler errors and resorted to Find !

Obviously C# syntax doesn’t do in VB. :slight_smile:

// Rolf

That should have worked just fine in C#

Yes, and I used it in the C# version, but I first tried getting the VB version working and stumbled on this syntax error and went for Find instead and so I never discovered that the index lookup (only) would have worked also in C#.

// Rolf

1 Like

Thanks, Steve!