How to collapse all sublayers in C++ SDK

@dale,

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:
image
not this which is what I am currently getting:

Regards,
Terry.

Hi Terry - in RhinoCommon I see this -

https://developer.rhino3d.com/wip/api/RhinoCommon/html/Overload_Rhino_DocObjects_Tables_LayerTable_ForceLayerVisible.htm

in case that helps.

-Pascal

Pascal,

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
    Parameters:
      layer (str): name of the layer to expand
      expand (bool): True to expand, False to collapse
    Returns:
      bool: True or False indicating success or failure
    Example:
      import rhinoscriptsyntax as rs
      if rs.IsLayerExpanded("Default"):
          rs.ExpandLayer( "Default", False )
    See Also:
      IsLayerExpanded
    """
    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?

Regards,
Terry.

Sorry - I misread - there is a property on a layer- ‘IsExpanded()’ that should (I think) do what you need.
https://developer.rhino3d.com/wip/api/RhinoCommon/html/P_Rhino_DocObjects_Layer_IsExpanded.htm

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

-Pascal

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

Nathan,

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:

Regards,
Terry.