Selection Events, Subobjects - Which one is Selected?

When a user selects a subobject, the SelectObject event fires for the object but I don’t see information for which subobject was actually selected.

How does a plugin determine this?

Example:
Create a rectangle, Curve->Rectangle, Corner to Corner.

Shift-Ctrl-leftclick one edge (say, the top one).

The SelectObject event fires for the entire polyline. How do you tell that a subobject was the actual selection and which one?

I don’t see anything else that looks relevant for events at the same level (Rhino Doc events where the SelectObject one is in the API docs). I also searched for ‘subobject’ in the C# developer examples.

I started this question out looking at 3D objects and simplified to the rectangle for this question.

First public beta of Rhino8.

You can access the selected sub-objects component indices like this:

private void RhinoDocOnSelectObjects(object sender, RhinoObjectSelectionEventArgs e)
{
  foreach(var rhObj in e.RhinoObjects)
    foreach(var ci in rhObj.GetSelectedSubObjects())
    {
       //code
    }
}
1 Like

This is a raw/incomplete implementation via c# script in gh.

It cheks 1. if the selected object is of type Brep, and 2. if it’s a sub-object of type BrepFace, and it adds the face geometry to a variable “geo” to output…
Different cases are not covered.

Note I managed to make it work by using try-catch trick…

Rhino 7.

private void RunScript(bool x, ref object A){
    if(x){
      RhinoDoc.SelectObjects += OnSelectObjects;
    }else{
      RhinoDoc.SelectObjects -= OnSelectObjects;
    }
    A = geo;
  }

  // <Custom additional code> 
  Rhino.Geometry.GeometryBase geo;
  void OnSelectObjects(object sender, Rhino.DocObjects.RhinoObjectSelectionEventArgs args){
    if(args.Selected){
      foreach(Rhino.DocObjects.RhinoObject obj in args.RhinoObjects){
        if(obj.ObjectType == Rhino.DocObjects.ObjectType.Brep){
          try{
            ComponentIndex[] ci = obj.GetSelectedSubObjects();
            if(ci != null & ci.Length > 0){
              foreach(ComponentIndex c in ci){
                if(c.ComponentIndexType == ComponentIndexType.BrepFace){
                  geo = ((Rhino.Geometry.GeometryBase) ((Brep) obj.Geometry).Faces[c.Index]);
                }
              }
            }
          }
          catch{}
          this.Component.ExpireSolution(true);
        }
      }
    }
    else{
      foreach(Rhino.DocObjects.RhinoObject obj in args.RhinoObjects){
      }
    }
  }

1 Like

Thanks!

And I found the type descriptor for the indices too, ComponentIndexType.