Get sub object ID when selecting a surface of a polysrf Rhino 6 C#



Hi everyone, I’m having an issue with subobject selection in Rhino 6 SR5 (the latest at the time of writing).
I have a (1) valid, closed solid polysurface with 6 surfaces. My plugin allows the user to select all of its surfaces by dragging the mouse, do some processing that generates some user data relative to each single surface individually, which is then visualized after clicking on the specific surface.
My problem is that if I select one or more surface in the first step, I get an ObjRef with a GeometryComponentIndex that is valid (from 0 to 5, since I have 6 surfaces, a BrepFace type), but if I do it after the processing, no matter the (single) surface I select, I get ID -1 and an invalid type as GeometryComponent.
This means I have no way of finding out which of the many surfaces available the user has selected. Please note that the surfaces share the same ObjectId, since they belong to the same polysurface.
Does anyone know if I’m doing something wrong? Does the User data get attached only to the top level object? maybe that’s the reason why I cannot get the “bottom” object?
I’m using the C# API.

Here the code:

Dictionary<ObjRef, Panel> panels = new Dictionary<ObjRef, Panel>();

GetObject go = new GetObject();
go.SetCommandPrompt(“Select surface to visualize.”);
go.GeometryFilter = ObjectType.Surface | ObjectType.Brep;
go.OneByOnePostSelect = true;
go.BottomObjectPreference = true;
go.SubObjectSelect = true;
go.DeselectAllBeforePostSelect = false;
go.ReferenceObjectSelect = false;
go.EnablePreSelect(false, true);
go.AlreadySelectedObjectSelect = true;

        while (go.Get() == GetResult.Object)
            ObjRef selObject = go.Object(0);                
            var subObj = selObject.Object().GetSelectedSubObjects();               
            var panel = panels.Where(x => x.Key.ObjectId == selObject.ObjectId &&                  
               x.Key.GeometryComponentIndex.Index == selObject.GeometryComponentIndex.Index).Single();                
            //Here the GeometryComponentIndexes don't match      
            MouldDisplayConduit pdc = new MouldDisplayConduit(doc, mould, panel.Value);


I have a small update to make, using this function I am able to get a surface with a valid GeometryComponentIndex, which I cannot get with GetObject(). Maybe some developer can give us some insight about why they work differently? Is there a bug in GetObject()?

The line I used is:

ObjRef selObject;
RhinoGet.GetOneObject(“Select surfaces”, false, ObjectType.Surface, out selObject);

(Steve Baer) #3

RhinoGet.GetOneObject uses a GetObject internally so you should be able to get the same results by using GetObject

public static Result GetOneObject(string prompt, bool acceptNothing, ObjectType filter, out ObjRef rhObject)
    rhObject = null;
    GetObject go = new GetObject();
    go.GeometryFilter = filter;
    Result rc = go.CommandResult();
    if (rc == Result.Success && go.ObjectCount > 0)
        rhObject = go.Object(0);
    return rc;