C#: How to select an object from code

Hello,

Is there a command/option in order to select objects from inside the code?
For example, assuming I have created 4 points (pt0, pt1, pt2, pt3) and 4 lines (line1, line2, lin3, line4), when I run the plugin I would like to get automatically selected line1, and then ask the user to do something.

Thank you :slight_smile:

Hi @Theofanis,

If you want to allow the user to pick one or more objects, then you can use the following:

Rhino.Input.RhinoGet.GetOneObject
Rhino.Input.RhinoGet.GetMultipleObjects
Rhino.Input.Custom.GetOption

The developer samples have many examples of the usage of these.

Does this help?

– Dale

Hey, thanks a lot for the reply.

Actually I don’t want the user to be able to select it. I would like it to be pre-selected by the plugin. That is, when I run the plugin, the points and the lines to be created, and a specific line to be already selected.

Hi @Theofanis,

There are a number of “Find” functions on the document’s ObjectTable. Some of them will work for you, depending on how you choose to look up these objects.

– Dale

Thanks again. Is it possible to give an example of how should I approach this? I’m fairly new to all this.

Hi @Theofanis,

Since you mentioned points, here is a simple example that finds all the points in the document and then prints their location:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var rh_objects = doc.Objects.FindByObjectType(ObjectType.Point);
  foreach (var rh_obj in rh_objects)
  {
    var rh_pt_obj = rh_obj as PointObject;
    if (null != rh_pt_obj)
    {
      RhinoApp.WriteLine("{0}, ({1})",
        rh_pt_obj.Id.ToString(), 
        rh_pt_obj.PointGeometry.Location.ToString()
        );
    }
  }
  return Result.Success;
}

– Dale