RhinoObject.IsSelected() Throws Exception when accessed


I am trying to check if a Sub-Object of a given Rhino Object is selected. It seems whenever I try to access the IsSelected property, RhinoCommon throws an Exception: This object cannot be modified because it is controlled by a document.

If anyone knows a better way to find out what Sub Objects are selected, I would love some help.

Thanks in advance,



Rhino.Runtime.DocumentCollectedException: This object cannot be modified because it is controlled by a document.
at Rhino.DocObjects.RhinoObject.ConstPointer()
at Rhino.DocObjects.RhinoObject.IsSelected(Boolean checkSubObjects)
at Matrix.Commands.ObjectActionsViewCommand.<>c__DisplayClass8.b__4(RhinoObject subObject) in d:\Matrix\trunk\source\Matrix\Matrix\Commands\ObjectActionsViewCommand.cs:line 155
at System.Linq.Enumerable.WhereArrayIterator1.MoveNext() at System.Collections.Generic.List1.InsertRange(Int32 index, IEnumerable1 collection) at Matrix.Commands.ObjectActionsViewCommand.<>c__DisplayClass8.<ShowF6Menu>b__3(RhinoObject parentObject) in d:\Matrix\trunk\source\Matrix\Matrix\Commands\ObjectActionsViewCommand.cs:line 154 at System.Collections.Generic.List1.ForEach(Action`1 action)
at Matrix.Commands.ObjectActionsViewCommand.d__10.MoveNext() in d:\Matrix\trunk\source\Matrix\Matrix\Commands\ObjectActionsViewCommand.cs:line 148
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.b__4(Object state)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)


IEnumerable allbObjects = RhinoDoc.ActiveDoc.Objects.GetObjectList(Rhino.DocObjects.ObjectType.AnyObject);
selectedSubObjects = new List();
allbObjects.ToList().ForEach(parentObject =>
var subObjectComponentIds = parentObject.GetSelectedSubObjects();
if (subObjectComponentIds != null && subObjectComponentIds.Length > 0)
var subs = parentObject.GetSubObjects();
subs.Where(subObject => subObject != null
&& subObject.IsSelected(false) == 1));

I have not tested your code, but this seems to work here…

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
  foreach (var rhino_object in doc.Objects.GetObjectList(ObjectType.AnyObject))
    ComponentIndex[] component_indices = rhino_object.GetSelectedSubObjects();
    if (null != component_indices && component_indices.Length > 0)
      foreach (ComponentIndex ci in component_indices)
        RhinoApp.WriteLine("Type = {0}, Index = {1}", 
  return Result.Success;
1 Like

I had to read that code a few times before it sunk in that ComponentIndex was not an integer…

Sorry, I should have read the docs better.

I didn’t see the whole ComponentIndexType enumeration.

That should work.