Objects selection via code is much slower than via viewport

Hi everyone,

I have a file that contains 2500 surfaces.
When I select those surfaces in viewport - they are selected immediately.

But when I try to select objects via rhinocommon, the selection takes 16-17 seconds.

This seems a bit confusing to me. Here are the methods I tried:

HashSet<Guid> objectIds - collection of object ids to select;

1:
RhinoDoc.ActiveDoc.Objects.Select(objectIds);

2: 
foreach (var id in objectIds)
{
       if (RhinoDoc.ActiveDoc.Objects.Find(id) != null)
               RhinoDoc.ActiveDoc.Objects.Select(id, true, true, true, true, true, true);
}

3: 
foreach (var id in objectIds)
{
       var obj = RhinoDoc.ActiveDoc.Objects.Find(id);
       if (obj != null)
              obj.Select(true, true, true, true, true, true);
}

4:
var refs = objectIds.Select(item => new ObjRef(item));
RhinoDoc.ActiveDoc.Objects.Select(refs);

Does anyone know why selection via code takes so long? Is there any way to improve the performance?

Here is the file: No Bueno 2 (3).3dm (9.4 MB)

Thanks,
Julia

Dunno, with Python/Rhinoscript it is almost immediate with either

rs.AllObjects(True)

or

rs.ObjectsByType(8,True)

?? --Mitch

Hi @Yuliya,

How about this?

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  foreach (var obj in doc.Objects)
    obj.Select(true);
  doc.Views.Redraw();
  return Result.Success;
}

– Dale

Hi @dale

Thank you for the feedback!
The sample you provided works fine, so there are no problems with the doc. Digging in to find out the reason of such behavior.

Thank you!

Hi

What if you wan to select with the GUIDs. so not to select anything else.

It is still super slow, Imagine because it needs to run by each GUID so when you have 6000 it just takes for ever

Any ideas on how to speed this up?

It shouldn’t take very long at all with only 6000 IDs. How are you doing this? Did you cut the screen redraw while selecting? Otherwise the screen will redraw after each object - and that will be slow. For 10K objects here, even looping through each GUID individually with rs.SelectObject(obj), it still takes only about a half second. 0.05 seconds if I use rs.SelectObjects(objs) on the whole list.

Hi

Thanks for the quick reply!!!

I’m trying to select within the rhino document.

So in C# if I do this:

Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects;

  bool nSelected = ot.Select(ID);

or this

Rhino.RhinoDoc.ActiveDoc.Objects.Select(ID);

or for that matter any other combination using GUIDs it takes foerever

If I do this:

  Rhino.RhinoApp.RunScript("SelAll", true);

It’s instant.

and then trying the python version. ( I’m not too good at python)

if I try this

import rhinoscriptsyntax as rs

if T :
rs.SelectObjects(ID)

Nothing get’s selected.

I’m trying to select it within the rhino doc, not bring it into the GH

I don’t know if I’m making too much sense

Thanks for your help :slight_smile: