C# DeleteObjectbyName component

Hi everyone,

I’m new and currently diving into C# for grasshopper, and so, maybe my question is very simple.

There is any way to code a C# grasshopper component that can Delete an object on the rhinoDoc simply by his name, and return a output boolean ?

any piece of code to understand how it works?

Thank’s for your time.

There is probably better code, but this seems to work. Be careful that if the name input is empty, the component will delete all objest without a name Attribute !

 private void RunScript(bool run, string name, ref object successful)
    if (run)
      List<bool> output = new List<bool>();
      IEnumerator ie = RhinoDoc.ActiveDoc.Objects.GetEnumerator();
      while (ie.MoveNext())
        RhinoObject ro = ie.Current as RhinoObject;
        if(ro.Attributes.Name == name)
          bool success = Rhino.RhinoDoc.ActiveDoc.Objects.Delete(ro, true);

      successful = output;


DeleteObjects.gh (3.6 KB)

Thank’s a lot @magicteddy !
Exactly what i was looking for !