Creating Sublayers
Windows only


You would like to create a “sublayer” (or a “child layer”) of a parent layer.


All layers have a layer id field, returned by ON_Layer::Id(), that uniquely identifies that layer. Layers also maintain a parent id field, returned by ON_Layer::ParentLayerId(), that identifies the layer’s parent. If a layer’s parent id is a null UUID, then the layer does not have a parent and, thus, is considered a root layer.


The following sample demonstrates how to add a parent layer then then add a child layer to that parent.

CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
  CRhinoLayerTable& layer_table = context.m_doc.m_layer_table;

  // Define parent layer
  ON_Layer parent_layer;

  // Add parent layer
  int parent_layer_index = layer_table.AddLayer(parent_layer);
  if (parent_layer_index >= 0) 
    // Get the layer we just added
    const CRhinoLayer& layer = layer_table[parent_layer_index];

    // Define child layer
    ON_Layer child_layer;

    // Assign parent layer's id as child's parent id

    // Add child layer

  return CRhinoCommand::success;