Invert selection in RhinoCommon

I am creating a command for layout drawing using Rhinocommon C#

The user selects the objects to show in a layout viewport. I want that viewport to hide everything else apart from what has been selected. To do that I need the list of all objects that are not being selected. Is there a way to invert the selected objects easily?

How about something like this:

public void HideUnselected(Rhino.RhinoDoc doc)
    foreach(var obj in doc.Objects)
      if(obj.IsSelected(true) == 0)
        doc.Objects.Hide(obj, false);
1 Like

This should do it:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
  var filter = new ObjectEnumeratorSettings
    NormalObjects = true,
    LockedObjects = false,
    HiddenObjects = false,
    ActiveObjects = true,
    ReferenceObjects = true

  var rh_objects = doc.Objects.FindByFilter(filter);
  foreach (var rh_obj in rh_objects)
    var select = 0 == rh_obj.IsSelected(false) && rh_obj.IsSelectable();


  return Result.Success;
1 Like