I can’t seem to find clear documentation for the rhinoscriptsyntax’s (rs for short) coerce methods in the rs method documentation website: https://developer.rhino3d.com/api/RhinoScriptSyntax/#collapse-IsBrep. While a brief explanation does show up when typing the specific method in the Rhino Python scripting window, it still leaves me with a couple of questions.
My understanding is that given a guid, rs.coerceX methods return the actual object. However, I’m wondering if the exact object that is specified is returned or a morphed version of it? My confusion stems from the scenario below.
I have an extrusion object’s guid. rs.IsBrep(extrusion object’s guid) returns True, so I’m assuming that extrusion objects are first Extrusions, and then Breps (please correct me if I’m wrong). I want this exact extrusion object (instead of its guid), but as a brep object so that I can pass it into methods that require breps as arguments.
However, when I call rs.coercegeometry(guid), I get an object of type Extrusion, not Brep. When I call rs.coercebrep(guid), I do get a brep obj that can be passed into methods fine, but I’m worried that this brep obj is not the original extrusion obj? Do these two objects have the exact same features? Has anything been changed? Are they the exact same object, just with type changed?
Yes, I can see how this might be somewhat confusing… A couple of things to note:
Some of the rhinoscriptsyntax methods accept extrusions as breps, as extrusion objects are supposed to be “transparent” - many methods are supposed to operate on either breps or extrusions without you having to specifically call them out separately. This is not true for most RhinoCommon methods, where you have to specifically code for extrusions or breps or both.
The rs.coerce… methods are specifically designed to take diverse input and try to output the object type desired. That does mean converting an extrusion to a brep if you use rs.coercebrep() - below is the code for rs.coercebrep:
def coercebrep(id, raise_if_missing=False):
"""attempt to get polysurface geometry from the document with a given id
Parameters:
id = id to be coerced into a brep
raise_if_missing [opt] = True or False
Returns:
a Rhino.Geometry.Brep
Example:
See Also:
"""
geom = coercegeometry(id, False)
if isinstance(geom, Rhino.Geometry.Brep): return geom
if isinstance(geom, Rhino.Geometry.Extrusion): return geom.ToBrep(True)
if raise_if_missing: raise ValueError("unable to convert %s into Brep geometry"%id)
Note the next to last line: geom.ToBrep(True) - that converts your extrusion into a Brep if it can. Most of the other surface geometry types in RhinoCommon have a ToBrep() method.
It’s not the original object… it’s a converted copy. It should have been converted ‘exactly’, though.
No. In converting an extrusion to a brep, the extrusion will lose its unique extrusion attributes (like the original profile and extrusion axis) but gain brep attributes. But remember, you are working with virtual geometry here in RhinoCommon. Nothing in the file has actually been altered, you just have a new (virtual) object you can work with.
I second this. I just spend 20 minutes trying to search through the Python side window (having it not alphabetical but having to dig through all categories didn’t help), the developer website and eventually the Rhino forums until I found this topic here.