Make GrandParent Layer

Hello. I’m working with c# in Visual Studio, and make plugin to use in Rhino
In my Office we usually use 2 depths or 3 depths layer
like

Building 1001

    Room no 101
               geom_wall
               geom_win
               geom_ent
    Room no 102
               geom_wall
               geom_win
               geom_ent
    Outline

So, I wanted to automate that.
I succeeded to do this
get geom_wall > Room no 101 – geom_wall
get geom_win > Room no 101 – geom_win
get geom_ent > Room no 101 – geom_ent

But it was different problem to make Building1001
I couldn’t find way to group Parents Layers (Room101 Room102 Outline) to GrandParent Layer(Buildingh1001)

Is there any way to create grand parent layer and connect it with parent layer?
or should i create grandparent layer first and make Room101 Room102 Outline in it and change layers of all objects?

Did you check:
https://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_DocObjects_Layer_ParentLayerId.htm

the file includes a helpful example.

As you use identical names in the lowest hierachie, make sure you generate grandparent (Building) first, then parents (rooms), then Childs (Geom_…)

hope that helps - kind regards - tom

Hi @slee.zenerate.ai,

Does this help?

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var room_layers = new [] { "Room no 101", "Room no 102" };
  var geometry_layers = new[] { "geom_wall", "geom_win", "geom_ent" };

  var root_id = AddLayer(doc, "Building 1001", Guid.Empty);
  if (root_id != Guid.Empty)
  {
    foreach (var room_layer in room_layers)
    { 
      var room_id = AddLayer(doc, room_layer, root_id);
      if (room_id != Guid.Empty)
      {
        foreach (var geometry_layer in geometry_layers)
          AddLayer(doc, geometry_layer, room_id);
      }
    }
    AddLayer(doc, "Outline", root_id);
  }
  return Result.Success;
}

private Guid AddLayer(RhinoDoc doc, string layerName, Guid parentId)
{
  var layer = new Layer
  {
    Name = layerName,
    ParentLayerId = parentId
  };

  var layer_index = doc.Layers.Add(layer);
  return (layer_index >= 0 && layer_index < doc.Layers.Count)
    ? doc.Layers[layer_index].Id
    : Guid.Empty;
}

– Dale

Thank you for recommendation~!
I’ve already read that and I got some clues from it.
I find layer is much more easier and intuitive when we dealing with layer window in Rhino
Can layer be related like they are in Layer Window in Rhino (like Drag and drop > make parent child connection)? I hope that happen in Rhinocommon dll.

@dale Thank you!
I think this is a good strategy using Arrays to build a structure of this Layers.
I’ll try that today! Thank you again!