Rhinocommon Select Method

rhinocommon

#1

Hi,

I am using the ObjectTable.Select(IEnumerable objectIds) method to select multiple objects in Rhino. However, the select process is very slow for a large amount of objects when the object properties page is open. It seems like the method is adding objects to selection one by one and updating the properties page accordingly. I would like to know if there is any way to avoid this behavior when selecting multiple objects.

Thanks,
Alan


(Menno Deij - van Rijswijk) #2

Have you tried to do RhinoDoc.ActiveDoc.Views.RedrawEnabled = false; during the update?


#3

Disable the redraw does not help.
Alan


(Dale Fugier) #4

If you are doing your selection from a modeless UI, then I suggest creating a hidden command and then have your modeless UI run your hidden command using RhinoApp.RunScript.

More info: the ObjectProperties panel is disable during the running of commands. But if your using a modeless UI, then the panel doesn’t know to disable itself.

Hidden commands are declared like this:

[System.Runtime.InteropServices.Guid("<your_guid_here>"), CommandStyle(Style.Hidden)]
public class MyHiddenCommand : Command
{

Let me know if you need an example…


#5

Dale,

Thanks. Using a hidden command works.

Alan


#6

Dale,

how would an example look like if you have either a list of all ids or a list of all objref?

Thanks
Christian


#7

Dale,

I solved it.

using Rhino;
using Rhino.Commands;
using System.Collections.Concurrent;
using Rhino.DocObjects;
using System.Linq;
using System;

namespace Lala.Commands
{
    [System.Runtime.InteropServices.Guid("A3834458-E805-438C-8FC0-7987B71B0DA2"), CommandStyle(Style.Hidden)]
    public class RC_HiddenSelect : Command
    {
        static ConcurrentQueue<ObjRef> _selObjects;

        static RC_HiddenSelect _instance;
        public RC_HiddenSelect()
        {
            _instance = this;
        }

        ///<summary>The only instance of the RC_HiddenSelect command.</summary>
        public static RC_HiddenSelect Instance
        {
            get { return _instance; }
        }
        
        public static ConcurrentQueue<ObjRef> SelObjects
        {
            get { return _selObjects; }
            set { _selObjects = value; }
        }

        public override string EnglishName
        {
            get { return "HiddenSelectByID"; }
        }

        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            try
            {
                RhinoDoc.ActiveDoc.Objects.Select(_selObjects.ToList(), true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return Result.Success;
        }
    }
}

Thanks for the hint.

Christian