Using CreatePatch in RhinoCommon without a starting surface

I’m trying to use CreatePatch to create a surface with RhinoCommon (the third version which seems to best match the patch command in rhino). I don’t want to have a starting surface, so I tried just putting in nothing, but I get an error…

Dim TestBrep = Rhino.Geometry.Brep.CreatePatch({Curve1, Curve2, Curve3}, Nothing, 30, 10, True, True, 1, 1, Nothing, Nothing, Nothing)

What is the correct way to use this command without a starting surface?

Thanks,
Sam

If you don’t have a starting surface, then you need to use the version of CreatePatch that uses a plane with u * v spans.

static Brep CreatePatch(
  IEnumerable<GeometryBase> geometry, 
  int uSpans, 
  int vSpans, 
  double tolerance
  );

Hi Dale,

If I use that version of the command, I get a different result than I do when running patch in Rhino (in particular the edge doesn’t match up with the perimeter curve included in the input geometry no matter what tolerance I use). Also, that version of the command is missing many of the inputs that the command in rhino has.

Perhaps I could just use Rhino.RhinoApp.RunScript( to get access to the command in Rhino, though I would rather not…

thanks,
Sam

I was wondering about this problem too.

To simulate the script patch as best as possible i was using the version of the command without the starting surface. I then take the inner surface from the result and use it as the starting surface to the third command.

This way I can set all the parameters as in the script with the starting surface created from Rhino.

This is not a good solution obviously, but the point is that, even doing all of this I have the same problem as Sam. The patch doesn’t match with the perimeter while the script version works perfectly.

Can you provide sample geometry, the parameters you use as input to the Patch command, and sample code that calls CreatePatch?

Hi Dale,

Below is the code. Attached is the geometry. The red surface already in the doc was created with the patch function within Rhino. A jpg of the settings is attached.

Thanks,
Sam

PatchTest.3dm (87.5 KB)

Dim CurvesObjRefs() As Rhino.DocObjects.ObjRef
Rhino.Input.RhinoGet.GetMultipleObjects(“Select Curves For Patch”, True, Rhino.DocObjects.ObjectType.Curve, CurvesObjRefs)
Dim Curves As New List(Of Rhino.Geometry.Curve)
For Each CurveObjRef In CurvesObjRefs
Curves.Add(TryCast(CurveObjRef.Geometry, Rhino.Geometry.Curve))
Next
Dim PatchBrep = Rhino.Geometry.Brep.CreatePatch(Curves, 30, 10, doc.ModelAbsoluteTolerance)
doc.Objects.AddBrep(PatchBrep)

@lowell, any chance you have time to look into this?

The RhinoCommon Patch stuff uses completely different code than the Patch command. But you should be able to produce surfaces that are nearly identical.

The function that takes no starting surface makes up a bunch of the detailed arguments. They look reasonable, except that the starting surface pull (see the arguments to the version of CreatePatch that exposes all controls) is set to 1, which makes the plane that gets cooked up have an influence on where the surface goes. If I change that to 0 (in a test build) I get virtually the same surface within the same tolerance to the input curves as with the command except that the grid is shifted sideways a little because the plane is cooked up a little differently.

Thus, the solution is for the version of CreatePatch that exposes all controls with the exception of the surface argument. I’l add something to the wish list.

OK, thanks for looking into it.
Sam

In the mean time I am just scripting the patch command (see below). It gets me the shape I want, but there are a couple problems.
First, it results in two identical surfaces rather than one surface… Any idea why this happens?
Second, in some cases my plugin has to delete the construction curves and create new ones, giving the new curves the attribute names so the patch is done on the new curves. But for some reason, the scripted patch command still builds the surface from the original curves, even though they have been deleted. Maybe I have to purge the original curves somehow?

Thanks,
Sam

Rhino.RhinoApp.RunScript("_selnone _-selname CLb -selname CLbc -selname CBGp -selname CIGp _-patch pointspacing=1 uspans=50 vspans=15 stiffness=1 adjusttangency=yes automatictrim=yes _enter _selnone ", False)

Whoops, I was making some silly mistakes. I was forgetting to put “scriptrunner” at the top of my command (can’t count how many times I have done that, maybe it would be useful if the command templates had that in it by default). The other was even dumber so won’t mention it :frowning:

Thanks,
Sam

I just added the code to RhinoCommon to make it so passing null (or Nothing in VB) for the startingSurface is allowed. This will be available in SR10

Great that this is being implemented in the next SR… I’ve just come across the same problem myself, and wished I could use the RhinoCommon command without including a start surface. Looking forward to SR10 !

Great, thanks!

I have SR10 via the latest service release candidate, and so I can specify nothing in the rhinocommon patch command for the start surface now. However, the resulting surface is different from the one I get when I use patch from the command prompt.

Perhaps it is because the settings are a bit different between the rhinocommon patch and the command prompt patch. Where the former has flexibility and surface pull, the later has stiffness. I’ve attached an image with the settings for the patch command from the command prompt. I’ve also attached the sample 3dm model. Finally, below is the rhinocommon code that I want to duplicate the results with. Any idea how I can change the rhinocommon code to get a better result? Particularly at the front where the patch doesn’t come close to the boundary…

Thanks,
Sam

Dim CurvesObjRefs() As Rhino.DocObjects.ObjRef
Rhino.Input.RhinoGet.GetMultipleObjects(“Select Curves For Patch”, True, Rhino.DocObjects.ObjectType.Curve, CurvesObjRefs)
Dim Curves As New List(Of Rhino.Geometry.Curve)
For Each CurveObjRef In CurvesObjRefs
Curves.Add(TryCast(CurveObjRef.Geometry, Rhino.Geometry.Curve))
Next
Dim PatchBrep = Rhino.Geometry.Brep.CreatePatch(Curves, Nothing, 30, 10, True, True, 1, 1, 0, {True, True, True, True}, doc.ModelAbsoluteTolerance)
doc.Objects.AddBrep(PatchBrep)
doc.Views.Redraw()

PatchTest.3dm (87.5 KB)