All:
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,
Jason
Exception:
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.List
1.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.List
1.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)
Code:
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();
selectedSubObjects.AddRange(
subs.Where(subObject => subObject != null
&& subObject.IsSelected(false) == 1));
}
});