def AddHatches(curve_ids, hatch_pattern=None, scale=1.0, rotation=0.0): """Creates one or more new hatch objects a list of closed planar curves Parameters: curve_ids = identifiers of the closed planar curves that defines the boundary of the hatch objects hatch_pattern[opt] = name of the hatch pattern to be used by the hatch object. If omitted, the current hatch pattern will be used scale[opt] = hatch pattern scale factor rotation[opt] = hatch pattern rotation angle in degrees. Returns: identifiers of the newly created hatch on success None on error """ id = rhutil.coerceguid(curve_ids, False) if id: curve_ids = [id] index = scriptcontext.doc.HatchPatterns.CurrentHatchPatternIndex if hatch_pattern and hatch_pattern!=index: if isinstance(hatch_pattern, int): index = hatch_pattern else: index = scriptcontext.doc.HatchPatterns.Find(hatch_pattern, True) if index<0: return scriptcontext.errorhandler() curves = [rhutil.coercecurve(id, -1, True) for id in curve_ids] rotation = Rhino.RhinoMath.ToRadians(rotation) hatches = Rhino.Geometry.Hatch.Create(curves, index, rotation, scale) if not hatches: return scriptcontext.errorhandler() ids = [] for hatch in hatches: id = scriptcontext.doc.Objects.AddHatch(hatch) if id==System.Guid.Empty: continue ids.append(id) if not ids: return scriptcontext.errorhandler() scriptcontext.doc.Views.Redraw() return ids
def PullCurveToMesh(mesh_id, curve_id): """Pulls a curve to a mesh. The function makes a polyline approximation of the input curve and gets the closest point on the mesh for each point on the polyline. Then it "connects the points" to create a polyline on the mesh Parameters: mesh_id (guid): identifier of mesh that pulls curve_id (guid): identifier of curve to pull Returns: guid: identifier new curve on success None: on error Example: import rhinoscriptsyntax as rs mesh = rs.GetObject("Select mesh that pulls", rs.filter.mesh) curve = rs.GetObject("Select curve to pull", rs.filter.curve) rs.PullCurveToMesh( mesh, curve ) See Also: IsMesh """ mesh = rhutil.coercemesh(mesh_id, True) curve = rhutil.coercecurve(curve_id, -1, True) tol = scriptcontext.doc.ModelAbsoluteTolerance polyline = curve.PullToMesh(mesh, tol) if not polyline: return scriptcontext.errorhandler() rc = scriptcontext.doc.Objects.AddCurve(polyline) if rc==System.Guid.Empty: raise Exception("unable to add polyline to document") scriptcontext.doc.Views.Redraw() return rc
def PullCurveToMesh(mesh_id, curve_id): """Pulls a curve to a mesh. The function makes a polyline approximation of the input curve and gets the closest point on the mesh for each point on the polyline. Then it "connects the points" to create a polyline on the mesh Parameters: mesh_id = identifier of mesh that pulls curve_id = identifier of curve to pull Returns: Guid of new curve on success None on error Example: import rhinoscriptsyntax as rs mesh = rs.GetObject("Select mesh that pulls", rs.filter.mesh) curve = rs.GetObject("Select curve to pull", rs.filter.curve) rs.PullCurveToMesh( mesh, curve ) See Also: IsMesh """ mesh = rhutil.coercemesh(mesh_id, True) curve = rhutil.coercecurve(curve_id, -1, True) tol = scriptcontext.doc.ModelAbsoluteTolerance polyline = curve.PullToMesh(mesh, tol) if not polyline: return scriptcontext.errorhandler() rc = scriptcontext.doc.Objects.AddCurve(polyline) if rc==System.Guid.Empty: raise Exception("unable to add polyline to document") scriptcontext.doc.Views.Redraw() return rc
def GetPointOnCurve(curve_id, message=None): """Pauses for user input of a point constrainted to a curve object Parameters: curve_id (guid): identifier of the curve to get a point on message (str, optional): a prompt of message Returns: point: 3d point if successful None: on error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Pick a curve") if rs.IsCurve(obj): point = rs.GetPointOnCurve(obj, "Point on curve") if point: rs.AddPoint(point) See Also: GetPoint GetPointOnMesh GetPointOnSurface GetPoints """ curve = rhutil.coercecurve(curve_id, -1, True) gp = Rhino.Input.Custom.GetPoint() if message: gp.SetCommandPrompt(message) gp.Constrain(curve, False) gp.Get() if gp.CommandResult()!=Rhino.Commands.Result.Success: return scriptcontext.errorhandler() pt = gp.Point() gp.Dispose() return pt
def AddHatches(curve_ids, hatch_pattern=None, scale=1.0, rotation=0.0): """Creates one or more new hatch objects a list of closed planar curves Parameters: curve_ids = identifiers of the closed planar curves that defines the boundary of the hatch objects hatch_pattern[opt] = name of the hatch pattern to be used by the hatch object. If omitted, the current hatch pattern will be used scale[opt] = hatch pattern scale factor rotation[opt] = hatch pattern rotation angle in degrees. Returns: identifiers of the newly created hatch on success None on error """ id = rhutil.coerceguid(curve_ids, False) if id: curve_ids = [id] index = scriptcontext.doc.HatchPatterns.CurrentHatchPatternIndex if hatch_pattern and hatch_pattern != index: if isinstance(hatch_pattern, int): index = hatch_pattern else: index = scriptcontext.doc.HatchPatterns.Find(hatch_pattern, True) if index < 0: return scriptcontext.errorhandler() curves = [rhutil.coercecurve(id, -1, True) for id in curve_ids] rotation = Rhino.RhinoMath.ToRadians(rotation) hatches = Rhino.Geometry.Hatch.Create(curves, index, rotation, scale) if not hatches: return scriptcontext.errorhandler() ids = [] for hatch in hatches: id = scriptcontext.doc.Objects.AddHatch(hatch) if id == System.Guid.Empty: continue ids.append(id) if not ids: return scriptcontext.errorhandler() scriptcontext.doc.Views.Redraw() return ids
def AddPlanarMesh(object_id, delete_input=False): """Creates a planar mesh from a closed, planar curve Parameters: object_id (guid): identifier of a closed, planar curve delete_input (bool, optional) if True, delete the input curve defined by object_id Returns: guid: id of the new mesh on success None: on error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select planar curves to build mesh", rs.filter.curve) if obj: rs.AddPlanarMesh(obj) See Also: IsCurveClosed IsCurvePlanar """ curve = rhutil.coercecurve(object_id, -1, True) tolerance = scriptcontext.doc.ModelAbsoluteTolerance mesh = Rhino.Geometry.Mesh.CreateFromPlanarBoundary(curve, Rhino.Geometry.MeshingParameters.Default, tolerance) if not mesh: return scriptcontext.errorhandler() if delete_input: id = rhutil.coerceguid(delete_input, True) rc = scriptcontext.doc.Objects.Replace(id, mesh) else: rc = scriptcontext.doc.Objects.AddMesh(mesh) if rc==System.Guid.Empty: raise Exception("unable to add mesh to document") scriptcontext.doc.Views.Redraw() return rc
def GetPointOnCurve(curve_id, message=None): """Pauses for user input of a point constrainted to a curve object Parameters: curve_id = identifier of the curve to get a point on message [opt] = a prompt of message Returns: 3d point if successful None on error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Pick a curve") if rs.IsCurve(obj): point = rs.GetPointOnCurve(obj, "Point on curve") if point: rs.AddPoint(point) See Also: GetPoint GetPointOnMesh GetPointOnSurface GetPoints """ curve = rhutil.coercecurve(curve_id, -1, True) gp = Rhino.Input.Custom.GetPoint() if message: gp.SetCommandPrompt(message) gp.Constrain(curve, False) gp.Get() if gp.CommandResult()!=Rhino.Commands.Result.Success: return scriptcontext.errorhandler() pt = gp.Point() gp.Dispose() return pt
def CurveMeshIntersection(curve_id, mesh_id, return_faces=False): """Calculates the intersection of a curve object and a mesh object Parameters: curve_id = identifier of a curve object mesh_id = identifier or a mesh object return_faces[opt] = return both intersection points and face indices. If False, then just the intersection points are returned Returns: if return_false is omitted or False, then a list of intersection points if return_false is True, the a one-dimensional list containing information about each intersection. Each element contains the following two elements (point of intersection, mesh face index where intersection lies) None on error """ curve = rhutil.coercecurve(curve_id, -1, True) mesh = rhutil.coercemesh(mesh_id, True) tolerance = scriptcontext.doc.ModelAbsoluteTolerance polylinecurve = curve.ToPolyline(0, 0, 0, 0, 0.0, tolerance, 0.0, 0.0, True) pts, faceids = Rhino.Geometry.Intersect.Intersection.MeshPolyline( mesh, polylinecurve) if not pts: return scriptcontext.errorhandler() pts = list(pts) if return_faces: faceids = list(faceids) return zip(pts, faceids) return pts
def CurveMeshIntersection(curve_id, mesh_id, return_faces=False): """Calculates the intersection of a curve object and a mesh object Parameters: curve_id = identifier of a curve object mesh_id = identifier or a mesh object return_faces[opt] = return both intersection points and face indices. If False, then just the intersection points are returned Returns: if return_false is omitted or False, then a list of intersection points if return_false is True, the a one-dimensional list containing information about each intersection. Each element contains the following two elements (point of intersection, mesh face index where intersection lies) None on error """ curve = rhutil.coercecurve(curve_id, -1, True) mesh = rhutil.coercemesh(mesh_id, True) tolerance = scriptcontext.doc.ModelAbsoluteTolerance polylinecurve = curve.ToPolyline(0,0,0,0,0.0,tolerance,0.0,0.0,True) pts, faceids = Rhino.Geometry.Intersect.Intersection.MeshPolyline(mesh, polylinecurve) if not pts: return scriptcontext.errorhandler() pts = list(pts) if return_faces: faceids = list(faceids) return zip(pts, faceids) return pts
def AddHatches(curve_ids, hatch_pattern=None, scale=1.0, rotation=0.0, tolerance=None): """Creates one or more new hatch objects a list of closed planar curves Parameters: curve_ids ([guid, ...]): identifiers of the closed planar curves that defines the boundary of the hatch objects hatch_pattern (str, optional): name of the hatch pattern to be used by the hatch object. If omitted, the current hatch pattern will be used scale (number, optional): hatch pattern scale factor rotation (number, optional): hatch pattern rotation angle in degrees. tolerance (number, optional): tolerance for hatch fills. Returns: list(guid, ...): identifiers of the newly created hatch on success None: on error Example: import rhinoscriptsyntax as rs curves = rs.GetObjects("Select closed planar curves", rs.filter.curve) if curves: if rs.IsHatchPattern("Grid"): rs.AddHatches( curves, "Grid" ) else: rs.AddHatches( curves, rs.CurrentHatchPattern() ) See Also: AddHatch CurrentHatchPattern HatchPatternNames """ __initHatchPatterns() id = rhutil.coerceguid(curve_ids, False) if id: curve_ids = [id] index = scriptcontext.doc.HatchPatterns.CurrentHatchPatternIndex if hatch_pattern is None: hatch_pattern = CurrentHatchPattern() if isinstance(hatch_pattern, int) and hatch_pattern != index: index = hatch_pattern else: pattern_instance = scriptcontext.doc.HatchPatterns.FindName( hatch_pattern) index = Rhino.RhinoMath.UnsetIntIndex if pattern_instance is None else pattern_instance.Index if index < 0: return scriptcontext.errorhandler() curves = [rhutil.coercecurve(id, -1, True) for id in curve_ids] rotation = Rhino.RhinoMath.ToRadians(rotation) if tolerance is None or tolerance < 0: tolerance = scriptcontext.doc.ModelAbsoluteTolerance hatches = Rhino.Geometry.Hatch.Create(curves, index, rotation, scale, tolerance) if not hatches: return scriptcontext.errorhandler() ids = [] for hatch in hatches: id = scriptcontext.doc.Objects.AddHatch(hatch) if id == System.Guid.Empty: continue ids.append(id) if not ids: return scriptcontext.errorhandler() scriptcontext.doc.Views.Redraw() return ids
def AddPlanarMesh(object_id, delete_input=False): """Creates a planar mesh from a closed, planar curve Parameters: object_id = identifier of a closed, planar curve delete_input[opt] = if True, delete the input curve defined by object_id Returns: id of the new mesh on success None on error """ curve = rhutil.coercecurve(object_id, -1, True) mesh = Rhino.Geometry.Mesh.CreateFromPlanarBoundary(curve, Rhino.Geometry.MeshingParameters.Default) if not mesh: return scriptcontext.errorhandler() rc = scriptcontext.doc.Objects.AddMesh(mesh) if rc==System.Guid.Empty: raise Exception("unable to add mesh to document") scriptcontext.doc.Views.Redraw() return rc
def GetPointOnCurve(curve_id, message=None): """Pauses for user input of a point constrainted to a curve object Parameters: curve_id = identifier of the curve to get a point on message [opt] = a prompt of message Returns: 3d point if successful None on error """ curve = rhutil.coercecurve(curve_id, -1, True) gp = Rhino.Input.Custom.GetPoint() if message: gp.SetCommandPrompt(message) gp.Constrain(curve, False) gp.Get() if gp.CommandResult()!=Rhino.Commands.Result.Success: return scriptcontext.errorhandler() pt = gp.Point() gp.Dispose() return pt
def GetPointOnCurve(curve_id, message=None): """Pauses for user input of a point constrainted to a curve object Parameters: curve_id = identifier of the curve to get a point on message [opt] = a prompt of message Returns: 3d point if successful None on error """ curve = rhutil.coercecurve(curve_id, -1, True) gp = Rhino.Input.Custom.GetPoint() if message: gp.SetCommandPrompt(message) gp.Constrain(curve, False) gp.Get() if gp.CommandResult() != Rhino.Commands.Result.Success: return scriptcontext.errorhandler() pt = gp.Point() gp.Dispose() return pt
def CurveMeshIntersection(curve_id, mesh_id, return_faces=False): """Calculates the intersection of a curve object and a mesh object Parameters: curve_id (guid): identifier of a curve object mesh_id (guid): identifier or a mesh object return_faces (bool, optional): return both intersection points and face indices. If False, then just the intersection points are returned Returns: list(point, ...): if return_false is omitted or False, then a list of intersection points list([point, number], ...): if return_false is True, the a one-dimensional list containing information about each intersection. Each element contains the following two elements [0] = point of intersection [1] = mesh face index where intersection lies None: on error Example: import rhinoscriptsyntax as rs curve = rs.GetObject("Select curve to intersect", rs.filter.curve) if curve: mesh = rs.GetObject("Select mesh to intersect", rs.filter.mesh) if mesh: cmx = rs.CurveMeshIntersection(curve, mesh, True) if cmx: for element in cmx: print element[0], ", Face index = ", element[1] rs.AddPoint(element[0]) See Also: MeshClosestPoint MeshMeshIntersection """ curve = rhutil.coercecurve(curve_id, -1, True) mesh = rhutil.coercemesh(mesh_id, True) tolerance = scriptcontext.doc.ModelAbsoluteTolerance polylinecurve = curve.ToPolyline(0, 0, 0, 0, 0.0, tolerance, 0.0, 0.0, True) pts, faceids = Rhino.Geometry.Intersect.Intersection.MeshPolyline( mesh, polylinecurve) if not pts: return scriptcontext.errorhandler() pts = list(pts) if return_faces: faceids = list(faceids) return zip(pts, faceids) return pts
def PullCurveToMesh(mesh_id, curve_id): """Pulls a curve to a mesh. The function makes a polyline approximation of the input curve and gets the closest point on the mesh for each point on the polyline. Then it "connects the points" to create a polyline on the mesh Paramters: mesh_id = identifier of mesh that pulls curve_id = identifier of curve to pull Returns: Guid of new curve on success None on error """ mesh = rhutil.coercemesh(mesh_id, True) curve = rhutil.coercecurve(curve_id, -1, True) tol = scriptcontext.doc.ModelAbsoluteTolerance polyline = curve.PullToMesh(mesh, tol) if not polyline: return scriptcontext.errorhandler() rc = scriptcontext.doc.Objects.AddCurve(polyline) if rc==System.Guid.Empty: raise Exception("unable to add polyline to document") scriptcontext.doc.Views.Redraw() return rc
def PullCurveToMesh(mesh_id, curve_id): """Pulls a curve object to a mesh object. The function makes a polyline approximation of the input curve and get the closest point on the mesh for each point on the polyline. Then it "connects the points" so that you have a polyline on the mesh Paramters: mesh_id = identifier of mesh object that pulls curve_id = identifier of curve object to pull Returns: Guid of new curve on success None on error """ mesh = rhutil.coercemesh(mesh_id, True) curve = rhutil.coercecurve(curve_id, -1, True) tol = scriptcontext.doc.ModelAbsoluteTolerance polyline = curve.PullToMesh(mesh, tol) if not polyline: return scriptcontext.errorhandler() rc = scriptcontext.doc.Objects.AddCurve(polyline) if rc==System.Guid.Empty: raise Exception("unable to add polyline to document") scriptcontext.doc.Views.Redraw() return rc
def CurveMeshIntersection(curve_id, mesh_id, return_faces=False): """Calculates the intersection of a curve object and a mesh object Parameters: curve_id = identifier of a curve object mesh_id = identifier or a mesh object return_faces[opt] = return both intersection points and face indices. If False, then just the intersection points are returned Returns: if return_false is omitted or False, then a list of intersection points if return_false is True, the a one-dimensional list containing information about each intersection. Each element contains the following two elements (point of intersection, mesh face index where intersection lies) None on error Example: import rhinoscriptsyntax as rs curve = rs.GetObject("Select curve to intersect", rs.filter.curve) if curve: mesh = rs.GetObject("Select mesh to intersect", rs.filter.mesh) if mesh: cmx = rs.CurveMeshIntersection(curve, mesh, True) if cmx: for element in cmx: print element[0], ", Face index = ", element[1] rs.AddPoint(element[0]) See Also: MeshClosestPoint MeshMeshIntersection """ curve = rhutil.coercecurve(curve_id, -1, True) mesh = rhutil.coercemesh(mesh_id, True) tolerance = scriptcontext.doc.ModelAbsoluteTolerance polylinecurve = curve.ToPolyline(0,0,0,0,0.0,tolerance,0.0,0.0,True) pts, faceids = Rhino.Geometry.Intersect.Intersection.MeshPolyline(mesh, polylinecurve) if not pts: return scriptcontext.errorhandler() pts = list(pts) if return_faces: faceids = list(faceids) return zip(pts, faceids) return pts
def PlaneCurveIntersection(plane, curve, tolerance=None): "Intersect an infinite plane and a curve object" plane = rhutil.coerceplane(plane, True) curve = rhutil.coercecurve(curve, True) if tolerance is None: tolerance = scriptcontext.doc.ModelAbsoluteTolerance intersections = Rhino.Geometry.Intersect.Intersection.CurvePlane(curve, plane, tolerance) if intersections: rc = [] for intersection in intersections: a = 1 if intersection.IsOverlap: a = 2 b = intersection.PointA c = intersection.PointA2 d = intersection.PointB e = intersection.PointB2 f = intersection.ParameterA g = intersection.ParameterB h = intersection.OverlapA[0] i = intersection.OverlapA[1] j = intersection.OverlapB[0] k = intersection.OverlapB[1] rc.append( (a,b,c,d,e,f,g,h,i,j,k) ) return rc
def PlaneCurveIntersection(plane, curve, tolerance=None): """Intersect an infinite plane and a curve object Parameters: plane = The plane to intersect. curve = The identifier of the curve object torerance [opt] = The intersection tolerance. If omitted, the document's absolute tolerance is used. Returns: A list of intersection information tuple if successful. The list will contain one or more of the following tuple: Element Type Description 0 Number The intersection event type, either Point (1) or Overlap (2). 1 Point3d If the event type is Point (1), then the intersection point on the curve. If the event type is Overlap (2), then intersection start point on the curve. 2 Point3d If the event type is Point (1), then the intersection point on the curve. If the event type is Overlap (2), then intersection end point on the curve. 3 Point3d If the event type is Point (1), then the intersection point on the plane. If the event type is Overlap (2), then intersection start point on the plane. 4 Point3d If the event type is Point (1), then the intersection point on the plane. If the event type is Overlap (2), then intersection end point on the plane. 5 Number If the event type is Point (1), then the curve parameter. If the event type is Overlap (2), then the start value of the curve parameter range. 6 Number If the event type is Point (1), then the curve parameter. If the event type is Overlap (2), then the end value of the curve parameter range. 7 Number If the event type is Point (1), then the U plane parameter. If the event type is Overlap (2), then the U plane parameter for curve at (n, 5). 8 Number If the event type is Point (1), then the V plane parameter. If the event type is Overlap (2), then the V plane parameter for curve at (n, 5). 9 Number If the event type is Point (1), then the U plane parameter. If the event type is Overlap (2), then the U plane parameter for curve at (n, 6). 10 Number If the event type is Point (1), then the V plane parameter. If the event type is Overlap (2), then the V plane parameter for curve at (n, 6). None on error Example: import rhinoscriptsyntax as rs curve = rs.GetObject("Select curve", rs.filter.curve) if curve: plane = rs.WorldXYPlane() intersections = rs.PlaneCurveIntersection(plane, curve) if intersections: for intersection in intersections: rs.AddPoint(intersection[1]) See Also: IntersectPlanes PlanePlaneIntersection PlaneSphereIntersection """ plane = rhutil.coerceplane(plane, True) curve = rhutil.coercecurve(curve, -1, True) if tolerance is None: tolerance = scriptcontext.doc.ModelAbsoluteTolerance intersections = Rhino.Geometry.Intersect.Intersection.CurvePlane(curve, plane, tolerance) if intersections: rc = [] for intersection in intersections: a = 1 if intersection.IsOverlap: a = 2 b = intersection.PointA c = intersection.PointA2 d = intersection.PointB e = intersection.PointB2 f = intersection.ParameterA g = intersection.ParameterB h = intersection.OverlapA[0] i = intersection.OverlapA[1] j = intersection.OverlapB[0] k = intersection.OverlapB[1] rc.append( (a,b,c,d,e,f,g,h,i,j,k) ) return rc