If I have a rhino.geometry.brep stored in the memory in a python script, is there a way to access the object reference (Rhino.DocObjects.ObjRef)? Sc.doc.objects.Find, coerceobject or adding it to the document return a brep or a guid, not the object reference - which I believe is necessary for sc.doc.Objects.Replace().
If it’s a Brep object, it does not have an object id, as it is not in the document.
You need to work the other way around, if it’s an object retrieved from the document via its guid, then you can then get its object reference (rhobj=rs.coercerhinoobject(id)
) or geometry (brep=rs.coercebrep(id) or brep=rhobj.geometry
)
The sc.doc.Objects.Replace()
method will replace an existing object in the document (via its id) with a new geometry object (such as a brep, curve, etc.), and the replacement will have the same id as the original.
It’s actually a brep created using MergeBrep, that merges two breps, so it’s not in the document. I think I tried adding it to the document and using coercerhinoobject but no dice - I’ll have to give it a go again to make sure, thanks!
You do that with
obj_id=sc.doc.Objects.AddBrep(brep)
– or replace an existing object with
sc.doc.Objects.Replace(exist_id, brep)
as outlined earlier.
But if the merged brep is invalid, either may fail.
So adding the object and coercing it returns a Rhino.DocObjects.BrepObject, not a Rhino:DocObjects.ObjRef - but given the Replace works with id’s it’s not an issue. Thanks for straightening me out.