Skip to content

Commit

Permalink
fixes RH-30409 rs.AddPatch
Browse files Browse the repository at this point in the history
  • Loading branch information
acormier committed May 18, 2015
1 parent d106f23 commit edd9931
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Scripts/rhinoscript/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,36 @@ def AddNurbsSurface(point_count, points, knots_u, knots_v, degree, weights=None)
scriptcontext.doc.Views.Redraw()
return id

def AddPatch(object_ids, uv_spans_tuple_OR_surface_object_id, tolerance=None, trim=True, point_spacing=0.1, flexibility=1.0, surface_pull=1.0, fix_edges=False):
geometry = List[Rhino.Geometry.GeometryBase]()
u_span = 10
v_span = 10
rc = None
id = rhutil.coerceguid(object_ids, False)
if id: object_ids = [id]
for object_id in object_ids:
rhobj = rhutil.coercerhinoobject(object_id, False, False)
if not rhobj: return None
geometry.Add( rhobj.Geometry )
if not geometry: return None

surface = None
if uv_spans_tuple_OR_surface_object_id:
if type(uv_spans_tuple_OR_surface_object_id) is tuple:
u_span = uv_spans_tuple_OR_surface_object_id[0]
v_span = uv_spans_tuple_OR_surface_object_id[1]
else:
surface = rhutil.coercesurface(uv_spans_tuple_OR_surface_object_id, False)

if not tolerance: tolerance = scriptcontext.doc.ModelAbsoluteTolerance
b = System.Array.CreateInstance(bool, 4)
for i in range(4): b[i] = fix_edges
brep = Rhino.Geometry.Brep.CreatePatch(geometry, surface, u_span, v_span, trim, False, point_spacing, flexibility, surface_pull, b, tolerance)
if brep:
rc = scriptcontext.doc.Objects.AddBrep(brep)
scriptcontext.doc.Views.Redraw()
return rc


def AddPipe(curve_id, parameters, radii, blend_type=0, cap=0, fit=False):
"""Creates a single walled surface with a circular profile around a curve
Expand Down
32 changes: 32 additions & 0 deletions Scripts/tests/AddPatchTests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import rhinoscriptsyntax as rs
import scriptcontext as sc
import unittest
import uuid
import Rhino.Geometry as g

def uniquestr():
return str(uuid.uuid4())

class AddPatchTests(unittest.TestCase):
def setUp(self):
pass

def test_InvalidArgumentsReturnsNone(self):
self.assertTrue(rs.AddPatch(uniquestr(), uniquestr()) == None)

def test_SimpleWithSurfaceAndDefaults(self):
id = rs.AddCircle((0,0,0), 20)
srf_id = rs.AddPlanarSrf(id)
pt_ids = rs.AddPoints([(-20,0,0), (0,20,0), (20,0,0)])
id = rs.AddPatch(pt_ids, srf_id)
brep = rs.coercebrep(id, True)
self.assertTrue(brep.IsSurface)

def test_SimpleWithUVSpansAndDefaults(self):
pt_ids = rs.AddPoints([(-20,0,0), (0,20,0), (20,0,0)])
id = rs.AddPatch(pt_ids, (10,10))
brep = rs.coercebrep(id, True)
self.assertTrue(brep.IsSurface)

suite = unittest.TestLoader().loadTestsFromTestCase(AddPatchTests)
unittestresult = unittest.TextTestRunner(verbosity=2).run(suite)

0 comments on commit edd9931

Please sign in to comment.