I haven’t found anything relevant in the docs. The only reference I’ve found to nested layers is the property ParentLayerId, but that’s a read-only property. If I try to change it I get an error.
I’ve also found LayerTable.AddPath(), which I thought might add a layer nested to another, but that method doesn’t exist in the js library.
@Daniel_González_Rein You need to set the parent layer id on the layer object. I’ve updated one of the samples to show you how to go about this, but here is a snippet:
//parent layer for Point Objects and Point Clouds
const pt_index = doc.layers().addLayer( 'Points', { r: 255, g: 0, b: 0, a: 255 } )
const pts_layer_id = doc.layers().findName( 'Points', '').id
//because we want to nest this layer, we need to set the parent layer id
const layer_pointObjects = new rhino.Layer()
layer_pointObjects.name = 'Point Objects'
layer_pointObjects.color = { r: 255, g: 0, b: 0, a: 255 }
layer_pointObjects.parentLayerId = pts_layer_id
const ptObject_layer_index = doc.layers().add( layer_pointObjects )
//because we want to nest this layer, we need to set the parent layer id
const layer_pointCloud = new rhino.Layer()
layer_pointCloud.name = 'Point Clouds'
layer_pointCloud.color = { r: 255, g: 0, b: 0, a: 255 }
layer_pointCloud.parentLayerId = pts_layer_id
const ptCloud_layer_index = doc.layers().add( layer_pointCloud )
I was using the index instead of the id, and was getting BindingError: Cannot pass non-string to std::string.
Now I’m getting the id using layers.findIndex(parentIdx).id.
It was a bit confusing that objects are added to a layer setting the layerIndex in the attributes, but layers are added to layers using the ID instead.