Doc.Objects.Delete Bug?

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)

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?

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.

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

It’s working Thanks again menno