Python patch

If you can’t figure out what a rhinoscriptsyntax function is doing, I’d recommend looking up its source code. rhinoscriptsyntax is a Python-style module wrapping RhinoCommon located (on my system) here:

C:\Users\AHD\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript

As you can see the function you’re calling is really just a bunch of Rhino document related boiler plate code around this RhinoCommon method:

def CurveBrepIntersect(curve_id, brep_id, tolerance=None):
    """Intersects a curve object with a brep object. Note, unlike the
    CurveSurfaceIntersection function, this function works on trimmed surfaces.
    Parameters:
      curve_id = identifier of a curve object
      brep_id = identifier of a brep object
      tolerance [opt] = distance tolerance at segment midpoints.
                        If omitted, the current absolute tolerance is used.
    Returns:
      List of identifiers for the newly created intersection curve and
      point objects if successful. None on error.            
    """
    curve = rhutil.coercecurve(curve_id, -1, True)
    brep = rhutil.coercebrep(brep_id, True)
    if tolerance is None or tolerance<0:
        tolerance = scriptcontext.doc.ModelAbsoluteTolerance
    rc, out_curves, out_points = Rhino.Geometry.Intersect.Intersection.CurveBrep(curve, brep, tolerance)
    if not rc: return scriptcontext.errorhandler()
    
    curves = []
    points = []
    for curve in out_curves:
        if curve and curve.IsValid:
            rc = scriptcontext.doc.Objects.AddCurve(curve)
            curve.Dispose()
            if rc==System.Guid.Empty: raise Exception("unable to add curve to document")
            curves.append(rc)
    for point in out_points:
        if point and point.IsValid:
            rc = scriptcontext.doc.Objects.AddPoint(point)
            points.append(rc)
    if not curves and not points: return None
    scriptcontext.doc.Views.Redraw()
    return curves, points

As discussed quite a lot around this board and the old GH forum, I’d personally recommend going with straight up RhinoCommon when coding up geometry stuff in GHPython. Can save yourself a lot of (guid-related) headaches, and perhaps also speed up your code a bit.

2 Likes