Doc.Objects.Delete Bug?


#1

I’m trying too delete a hidden object but I cant get it to work:

For Each obj As DocObjects.RhinoObject In doc.Objects
doc.Objects.Show(obj.Id, True)
doc.Objects.Unlock(obj.Id, True)
doc.Objects.Delete(New DocObjects.ObjRef(obj.Id), True)
Next

I create a plane and hide it in rhino then run the command. And It’s still there when I use the command show.
What am i doing wrong?


Delete a hidden objects
(Menno Deij - van Rijswijk) #2

doc.Objects only contains Visible items. You need to use doc.Objects.GetObjectList and set the ObjectEnumeratorSettings correctly. Then, unhide the object and delete it.

http://4.rhino3d.com/5/rhinocommon/html/M_Rhino_DocObjects_Tables_ObjectTable_GetObjectList.htm
http://4.rhino3d.com/5/rhinocommon/html/T_Rhino_DocObjects_ObjectEnumeratorSettings.htm

ObjectEnumeratorSettings s = new ObjectEnumeratorSettings
{
HiddenObjects = true
};
var hiddenObjects = doc.Objects.GetObjectList(s);
foreach(var obj in hiddenObjects)
{
   obj.IsHidden = false;
   obj.CommitChanges();
   doc.Objects.Delete(obj, true);
}

#3

It’s working Thanks again menno