Functionality of rs.coerceX Methods

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.

HTH, --Mitch

4 Likes