def _get_plane_aligned_to_surface(_surface): """Finds an Aligned Plane for Surface input Note, will try and correct to make sure the aligned plane's Y-Axis aligns to the surface and goes 'up' (world Z) if it can. Arguments: _surface: The Rhino surface to align with Returns: srfcPlane: A single Plane object, aligned to the surface """ # Get the UV info for the surface srfcPlane = rs.SurfaceFrame(_surface, [0.5, 0.5]) centroid = ghc.Area(_surface).centroid uVector = srfcPlane.XAxis vVector = srfcPlane.YAxis # Create a Plane aligned to the UV of the srfc lineU = ghc.LineSDL(centroid, uVector, 1) lineV = ghc.LineSDL(centroid, vVector, 1) srfcPlane = ghc.Line_Line(lineU, lineV) # Try and make sure its pointing the right directions if abs(round(srfcPlane.XAxis.Z, 2)) != 0: srfcPlane = ghc.RotatePlane(srfcPlane, ghc.Radians(90)) if round(srfcPlane.YAxis.Z, 2) < 0: srfcPlane = ghc.RotatePlane(srfcPlane, ghc.Radians(180)) return srfcPlane
def getSrfFrame(srf): domainU = rs.SurfaceDomain(srf, 0) domainV = rs.SurfaceDomain(srf, 1) u = domainU[1] / 2.0 v = domainV[1] / 2.0 point = rs.EvaluateSurface(srf, u, v) param = rs.SurfaceClosestPoint(srf, point) return rs.SurfaceFrame(srf, param)
def extframe(srf): crv = rs.DuplicateSurfaceBorder(srf, type=1) point = rs.EvaluateCurve(crv, 0) parameter = rs.SurfaceClosestPoint(srf, point) plane = rs.SurfaceFrame(srf, parameter) direction = rs.CurveTangent(crv, 0) newplane = rs.PlaneFromNormal(point, direction, plane.ZAxis) frame = sweepSec(crv, newplane, vec1) if crv: rs.DeleteObjects(crv) return frame
def set_part_base_plane(part): """returns an alinged plane at (U.5,V.5) of a planar surface""" x = True if x == True: #rs.IsPlaneSurface(part): normalizedParameter = (.5, .5) frameParameter = rs.SurfaceParameter(part, normalizedParameter) frame = rs.SurfaceFrame(part, frameParameter) return frame else: return "object is not a planar surface"
def isoframe(srf, uv, spacing, vec): points = intervalpts(srf, uv, spacing) sweeps = [] for i in points: point = rs.EvaluateSurface(srf, i[0], i[1]) parameter = rs.SurfaceClosestPoint(srf, point) plane = rs.SurfaceFrame(srf, parameter) crv = rs.ExtractIsoCurve(srf, parameter, flipBool(uv)) direction = rs.CurveTangent(crv, 0) newplane = rs.PlaneFromNormal(point, direction, plane.ZAxis) sweeps.append(sweepSec(crv, newplane, vec)) return sweeps
def SurfaceTensorField(srf_id, Nu, Nv): uDomain = rs.SurfaceDomain(srf_id, 0) vDomain = rs.SurfaceDomain(srf_id, 1) t = [] k = [] for i in range(Nu): u = uDomain[0] + (i/Nu)*(uDomain[1]-uDomain[0]) for j in range(Nv): v = vDomain[0]+(j/Nv)*(vDomain[1]-vDomain[0]) t.append( rs.SurfaceFrame(srf_id, (u,v)) ) k.append( rs.SurfaceCurvature(srf_id, (u,v))[5] ) return t,k
def extframe(srf, vec): frames = [] crv = rs.DuplicateSurfaceBorder(srf, type=1) rs.SimplifyCurve(crv) domain = rs.CurveDomain(crv) param = (domain[0] + domain[1]) / 2.0 rs.CurveSeam(crv, param) point = rs.EvaluateCurve(crv, 0) parameter = rs.SurfaceClosestPoint(srf, point) plane = rs.SurfaceFrame(srf, parameter) direction = rs.CurveTangent(crv, 0) newplane = rs.PlaneFromNormal(point, direction, plane.ZAxis) frame.append(sweepSec(crv, newplane, vec)) if crv: rs.DeleteObjects(crv) return frames
def contour (crvOffset): # get geometry surfaceId = rs.GetObject("pick surface to contour", 0, True, True) startPt = rs.GetPoint("base point of contours") endPt = rs.GetPoint("end point of contours") count = 0 reference = [] target = [] # make contours & store in newCrvs newCrvs = rs.AddSrfContourCrvs(surfaceId, (startPt, endPt), crvOffset) # output is a list of GUIDs. can't access raw points # divide the target surface printBed = rs.GetObject("pick surface for layout", 8, True, True) intCount = len(newCrvs) uDomain = rs.SurfaceDomain(printBed, 0) vDomain = rs.SurfaceDomain(printBed, 1) uStep = (uDomain[1] - uDomain[0]) / intCount for u in rs.frange(uDomain[0], uDomain[1], uStep): layout = rs.SurfaceFrame(printBed, [u,1]) target1 = layout[0] # set target to point inside of object - note this is a single point target2 = rs.PointAdd(target1,(0,10,0)) # this could be more parametric target.extend([target1, target2]) #print target # add text, reference and orient! # for orient, we need a list 3 points to reference and 3 points to target! # maybe reference should be curve origin crvPl[0] and midpoint? or else polyline verticies -- need to convert curve to polyline first? for crv in newCrvs: count += 1 # for label crvPl = rs.CurvePlane(crv) # plane for text rs.AddText(count, crvPl, 0.25) # should you label on the ground? #crvPl = rs.PointAdd(crvPl[0], (0,0,-1)) # if you wanted to offset text ref1 = rs.CurveMidPoint(crv) ref2 = crvPl[0] reference.extend([ref1, ref2])
def WhoFramedTheSurface(): surface_id = rs.GetObject("Surface to frame", 8, True, True) if not surface_id: return count = rs.GetInteger("Number of iterations per direction", 20, 2) if not count: return udomain = rs.SurfaceDomain(surface_id, 0) vdomain = rs.SurfaceDomain(surface_id, 1) ustep = (udomain[1] - udomain[0]) / count vstep = (vdomain[1] - vdomain[0]) / count rs.EnableRedraw(False) u = udomain[0] while u <= udomain[1]: v = vdomain[0] while v <= vdomain[1]: pt = rs.EvaluateSurface(surface_id, u, v) if rs.Distance(pt, rs.BrepClosestPoint(surface_id, pt)[0]) < 0.1: srf_frame = rs.SurfaceFrame(surface_id, [u, v]) rs.AddPlaneSurface(srf_frame, 1.0, 1.0) v += vstep u += ustep rs.EnableRedraw(True)
import rhinoscriptsyntax as rs idSurface = rs.GetObject("Surface to frame", 8, True, True) faces = [] intCount = rs.GetInteger("Number of iterations per direction", 20, 2) uDomain = rs.SurfaceDomain(idSurface, 0) vDomain = rs.SurfaceDomain(idSurface, 1) uStep = int((uDomain[1] - uDomain[0]) / intCount) vStep = int((vDomain[1] - vDomain[0]) / intCount) rs.EnableRedraw(False) for u in range(int(uDomain[0]), int(uDomain[1]), int(uStep)): for v in range(int(vDomain[0]), int(vDomain[1]), int(vStep)): pt = rs.EvaluateSurface(idSurface, u, v) srfFrame = rs.SurfaceFrame(idSurface, [u, v]) rs.AddPlaneSurface(srfFrame, 2.0, 2.0) #rs.AddEllipse(srfFrame, 1.0, 3.0) component = rs.GetObject("component to populate", rs.filter.mesh) faces = rs.MeshFaces(component, False) rs.AddMesh(faces, srfFrame) rs.EnableRedraw(True)
def sweepRail(srf, crv, vec, param, point): plane = rs.SurfaceFrame(srf, param) direction = rs.CurveTangent(crv, 0) newplane = rs.PlaneFromNormal(point, direction, plane.ZAxis) # if crv: rs.DeleteObjects(crv) return sweepSec(crv, newplane, vec)
uDomain = rs.SurfaceDomain(idSurface, 0) vDomain = rs.SurfaceDomain(idSurface, 1) # get size int from domain & / by intended count = increment between surfaces uStep = (uDomain[1] - uDomain[0]) / intCount vStep = (vDomain[1] - vDomain[0]) / intCount #print uStep #print vStep rs.EnableRedraw(False) # loop through size of surface by step increment in both u & v directions for u in rs.frange(uDomain[0], uDomain[1], uStep): for v in rs.frange(vDomain[0], vDomain[1], vStep): pt = rs.EvaluateSurface(idSurface, u, v) # get points at each domain step if rs.Distance(pt, rs.BrepClosestPoint(idSurface, pt)[0]) < 0.1: srfFrame = rs.SurfaceFrame( idSurface, [u, v]) # create ref plane at each division point newPlane = rs.AddPlaneSurface( srfFrame, 1.0, 1.0) # create surface at each ref plane # add height guideline from plane's origin to "ceiling" centerPt = rs.SurfaceAreaCentroid( newPlane) # locate center of each new plane limit = 10 # set "ceiling" endPt = limit - centerPt[0][ 2] # access z coordinate with the tuple rs.AddLine(centerPt[0], rs.PointAdd(centerPt[0], (0, 0, endPt))) rs.EnableRedraw(True) # refresh viewport at one time only
def surf_f(u, v): plane = rh.SurfaceFrame(id, (u, v)) if rh.IsPointOnSurface(id, plane.Origin): return f(fromPlane(plane)) else: return False