How to convert Rhino.Geometry into RhinoObject?

Hello all,
this might be a very basic question for everyone having more C# experience then I, but so far I havent found any tutorial explaining this:
How can I convert for example a Rhino.Geometry.Brep into an Rhino.DocObjects.ObjRef ?
I need the ObjRef or RhinoObject (?) for the delete function: ObjectTable.Delete Method (RhinoObject, Boolean)

Thanks!

You need to find the object by finding or iterating over all objects and check if the id is the one from your geometry then you can delete it.

well, to work with ids, I need to have a RhinoObject at the begining, right?. But the problem was how do i get from a Rhino.Geometry to a RhinoObject.

The only way I ever got an Rhino.Geometry into a RhinoObject was by FindByLayer() but i need a specific Object not the whole Layer. So I tried it with the FindByUserString(), but it doesnt seem to put any “findings” into my RhinoObject “srf”.

cube.brep.SetUserString(“delete”, “1”);
Rhino.DocObjects.RhinoObject srf;
srf = Rhino.RhinoDoc.ActiveDoc.Objects.FindByUserString(“delete”,“1”,true,true,true,Rhino.DocObjects.ObjectType.AnyObject);

you could compare the boundingbox of the object geometry and the geometry to get the object.

import Rhino as rh
import scriptcontext as sc


l1 = rh.Geometry.Line(1,2,3,4,5,6)
sc.doc.Objects.AddLine(l1)


for i in rh.RhinoDoc.ActiveDoc.Objects:
    if i.Geometry.GetBoundingBox(i).Equals(rh.Geometry.Line(1,2,3,4,5,6).BoundingBox):
        sc.doc.Objects.Purge(i)