Properties window slowing down object selection

Hello!

Whats the best way for selecting thousands of objects in Rhinocommon? I have an issue whereby automated selection is very slow as soon as the object properties window is open. I have tried a number of selection commands, along the lines of:

List<> nextGuids = new List<>() // thousands of guid objects - guids of objects in Rhino document

//Option 1
Rhino.RhinoDoc.ActiveDoc.Objects.Select(nextGuids);

//Option 2
foreach (Guid guid in nextGuids)
{
Rhino.RhinoApp.RunScript("_SelID " + guid, false);
}

//Option 3
foreach (Guid guid in nextGuids)
{
RhinoObject rO = Rhino.RhinoDoc.ActiveDoc.Objects.Find(guid);
if (rO != null)
{
rO.Select(true);
}
}

When the properties window is open, selection takes up to a minute for about 10000 objects. When closed, the same Operation only takes a few seconds. Is there a way to disable the properties window (or relevant event handlers) temporarily?

Thanks,

Daniel

Yeah thats possible to close that panel before the command and open it after again:

UI.Panels.ClosePanel(UI.PanelIds.ObjectProperties)

Think there is an Openpanel also there :smile:
Maybe to make it faster you can also try
  RhinoDoc.ActiveDoc.Views.RedrawEnabled = False

and at the end true. So the visual stuff will be shut down and activated later again. this Can make a command run a couple of times faster :wink:

thanks, yes, I’m already disabling redraws to speed things up.
Actually closing panels seems to be a bit cumbersome I guess. Also, I’d have to reopen them afterwards etc.
Maybe writing a custom Selection Command and passing the nextGuids list could help?
I guess this would put Rhino into the InCommand state and disable all sorts of things.
But I thought I’d ask if anyone knew of a leaner way of going about this…

in any case, I’ll use your advice for now, it seems to work well enough for now! Thanks!

       bool prop = Rhino.UI.Panels.IsPanelVisible(Rhino.UI.PanelIds.ObjectProperties);
       if (prop)
       {
           Rhino.UI.Panels.ClosePanel(Rhino.UI.PanelIds.ObjectProperties);
       }
       Rhino.RhinoDoc.ActiveDoc.Objects.Select(guidsNew);
       if (prop)
       {
           Rhino.UI.Panels.OpenPanel(Rhino.UI.PanelIds.ObjectProperties);
       }

Hello,

it appears this old issue has once again become relevant in Rhino 6.
Selecting many objects using Rhinocommon is very slow if the object properties dialog is open.

Selecting all objects in a dcoument using “_selAll” is fast, independently of whether the object properties dialog is open.
The doc.Objects.Select() functions are equally fast, but if the object properties dialog is open, the selection is followed by a delay of several seconds.

See below an attempt to time the functions. Tested on Rhino 6 SR 10.

Is there a way in RhinoCommon to reproduce the speed of “_selAll”?

Many thanks for any help!

Daniel

public class SelectionDebug : Command
{
    public SelectionDebug()
    {
        // Rhino only creates one instance of each command class defined in a
        // plug-in, so it is safe to store a refence in a static property.
        Instance = this;
    }

    ///<summary>The only instance of this command.</summary>
    public static SelectionDebug Instance
    {
        get;
        private set;
    }

    ///<returns>The command name as it appears on the Rhino command line.</returns>
    public override string EnglishName
    {
        get { return "SelectionDebug"; }
    }

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {

        IEnumerator<RhinoObject> ros = doc.Objects.GetEnumerator();
        List<Guid> nextGuids = new List<Guid>(); //guids of objects in Rhino document
        while (ros.MoveNext())
        {
            nextGuids.Add(ros.Current.Id);
        }

        Stopwatch sw = new Stopwatch();
        sw.Start();
        //Option 1
        Rhino.RhinoDoc.ActiveDoc.Objects.Select(nextGuids);
        sw.Stop();
        RhinoApp.WriteLine("option 1 took" + sw.ElapsedMilliseconds);
        sw.Restart();



        //Option 2
        foreach (Guid guid in nextGuids)
        {
            RhinoObject rO = Rhino.RhinoDoc.ActiveDoc.Objects.Find(guid);
            if (rO != null)
            {
                rO.Select(true);
            }
        }
        sw.Stop();
        RhinoApp.WriteLine("option 2 took" + sw.ElapsedMilliseconds);
        sw.Restart();



        Guid guidP = Rhino.UI.PanelIds.ObjectProperties;
        bool open = Rhino.UI.Panels.IsPanelVisible(guidP);

        if (open)
        {
            Rhino.UI.Panels.ClosePanel(guidP);
        }

        sw.Reset();
        
        sw.Start();
        //Option 1
        Rhino.RhinoDoc.ActiveDoc.Objects.Select(nextGuids);
        sw.Stop();
        RhinoApp.WriteLine("option 1b took" + sw.ElapsedMilliseconds);
        sw.Restart();



        //Option 2
        foreach (Guid guid in nextGuids)
        {
            RhinoObject rO = Rhino.RhinoDoc.ActiveDoc.Objects.Find(guid);
            if (rO != null)
            {
                rO.Select(true);
            }
        }
        sw.Stop();
        RhinoApp.WriteLine("option 2b took" + sw.ElapsedMilliseconds);
        sw.Restart();


        if (open)
        {
            Guid guid = Rhino.UI.PanelIds.ObjectProperties;
            Rhino.UI.Panels.OpenPanel(guid);

        }

        doc.Views.Redraw();

        return Result.Success;
    }

}
2 Likes