Python patch

I am trying to make a patch, but I do not know what they meant with a ‘Guid’ for the ‘rs.AddPatch()’ part .:sweat::unamused:

What am I doing wrong?

20190123 problem patch (13.6 KB)

It has been a while since last time I coded for Rhino, but isn’t there an attribute .id of the patch?

try cr[0].id

Try printing print cr[0] to see what you have got.
If the Brep intersection failed then you may have None

I think:

rs.AddPatch() needs a list of at least 2 items. Your are passing in the 0th item of the intersection curve list (cr[0]). Making some assumptions about the needed output, this might help:

import rhinoscriptsyntax as rs
import scriptcontext as sc

all_curves = []


for i, b in enumerate(breps):
    curves = rs.IntersectBreps(b, srf, sc.doc.ModelAbsoluteTolerance)
    print(i, curves)
    for c in curves:
brep_out = rs.AddPatch(all_curves, (span, span))


It intersects multiple breps with a surface, collects the intersection curves, and makes a patch from them. Set the brps input to list access. Not sure if that is what you are after though.

1 Like

Thank you for your response.
A question. What I try to achieve creating from a closed curve a surface. A closed curve which also could be one with more than four corners, so, a polysurface from curves.
Those curves picked from the intersections of the breps with the other surface. This with the idea in mind I can merge the surfaces.

However, do you know, is patch the best option for that because it seems to work differently than the component as in grasshopper?

I am sure I am doing something wrong, but looking at the span option which does not make the patch. I should put myself deeper into understanding ‘rs.Patch.’ Did you make those arcs on purpose not flat?

I want to merge the patches afterwards creating the patches.

20190123 problem patch (16.4 KB)

Hmm, you might try Intersect->Shape->Region Union. I haven’t used it previously but it seems like if you can guarantee each intersection set of lines can be closed and planar, then it might be able to curve-boolean to get the blue lines.

Another approach maybe is to solidify/boolean the shapes before intersecting.

Yes they were curved on purpose.

rs.Patch is just like the Rhino command Patch, I think, so if you can get that to work manually then that would be the first step. Spans parameter is to set the control points for the span. I think Patch is mainly for filling in surfaces to make them closed.

Hmmm… I think I am a step further, but I cannot find a way to merge the patches like with the component ‘region union.’

I am seriously trying to do it python because I need to implement it in
a larger script.

Do you might know a way to merge the patches? Even trying to let them all intersect won’t result in a merged result.

20190123 problem patch (14.5 KB)

Take a look at the output variable.

I don’t think I know the full scope, but you probably don’t need patches.

Here are some hints:

If you want to skip straight to a possible solution:

import rhinoscriptsyntax as rs
import scriptcontext as sc

all_curves = []

for i, b in enumerate(breps):
    crvs = rs.IntersectBreps(b, srf, sc.doc.ModelAbsoluteTolerance)
    for c in crvs:
        # check to make sure intersection curves are closed and planar
        if rs.IsCurveClosed(c) and rs.IsCurvePlanar(c):
# check curve list

curve_boolean = rs.CurveBooleanUnion(all_curves)

paper = rs.AddPlanarSrf(curve_boolean)


1 Like

:bird: take off :tada::tada::tada::tada:


Do you might know? Are those Guids points or curves or parameters?

I am trying to get the curves inside the brep.

My thought on that was, I get the parameters, cut the curves and look which curves are inside by the curves midpoint.

20190123 problem patch (16.6 KB)

I think you are appending empty lists for non-intersecting curves.
Maybe try:

1 Like

Thank you. :slight_smile: Also, do you know what kind of Guid objects these are?

You’re welcome :slight_smile:
Well according to the docs they represent an ‘intersection object’
Searching Google for rhino + ‘intersection object’ I find nothing so I presume they represent curves? I’m confused by the nesting structure though - I would expect this code to generate a flat list of guids but you seem to have a list containing:

  • An empty list
  • a list of 2 guids,
  • an empty list
  • a list of 2 guids
    :confused: Are your inputs simple curves or polylines?
1 Like

I know exploded the curves, but I get the same results. I cannot understand what it could be those Guid objects. I try to get the ‘inside the brep’ curves.

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.
      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.
      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)
            if rc==System.Guid.Empty: raise Exception("unable to add curve to document")
    for point in out_points:
        if point and point.IsValid:
            rc = scriptcontext.doc.Objects.AddPoint(point)
    if not curves and not points: return None
    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.


I do not understand why I do not get the curves out of it. Do you might know what I am doing wrong with rs.CurveBrepIntersect?

Oh, because they do not intersect one curve at once. But, when having a polyline, it still is the same problem. Does it interpret a polyline as many lines, do you ,might know that?

I am trying to get the curves inside the brep.
20190123 problem patch (18.9 KB)

Did you even try to understand the function that you’re calling? More specifically what it returns and under which circumstances, at least try to make a print(cr) statement after line 7.

Yes, but I do not understand the empty ones, the [ ] when doing print(cr).
I am not able the retrieve the inside curves.

That means that no intersection curves were found. Looks like you got some points though.