How to collapse all sublayers in C++ SDK


I have created many parent layers with sublayers in my C++ script. But this leaves all the sublayers expanded. How do I collapse all the sublayers using the C++ SDK?

I want to see this after the script runs:
not this which is what I am currently getting:


Hi Terry - in RhinoCommon I see this -

in case that helps.



That reference is helpful for changing the visibility of layers in a viewport. But it does not affect collapsing and expanding layers in the Layers tab that I pictured above. I need a way for the C++ script to be able to do what I manually do in the Layers tab when I click on the Down Arrow in front of a parent layer name.

This shows the needed command in Rhinocommon syntax:

def ExpandLayer( layer, expand ):
    """Expands a layer. Expanded layers can be viewed in Rhino's layer dialog
      layer (str): name of the layer to expand
      expand (bool): True to expand, False to collapse
      bool: True or False indicating success or failure
      import rhinoscriptsyntax as rs
      if rs.IsLayerExpanded("Default"):
          rs.ExpandLayer( "Default", False )
    See Also:
    layer = __getlayer(layer, True)
    if layer.IsExpanded==expand: return False
    layer.IsExpanded = expand
    return True

Perhaps you know a way to execute a Rhinocommon command from C++?

@dale, any suggestions?


Sorry - I misread - there is a property on a layer- ‘IsExpanded()’ that should (I think) do what you need.

If not, I’ll back away and wait for the bigger brains.


Set m_bExpanded to false on the ON_Layer instance.

Here an example for C++ to change layers, in your case you just want to changem_bExpanded. But using ModifyLayer on the layer table is necessary.

Here another sample


Using your suggestion, I found these 2 lines did the trick:

parent_layer.m_bExpanded = false;
layer_table.ModifyLayer(parent_layer, parent_index);

By the way, the documentation for m_bExpanded is bonkers: