def Revolve(self): self.Join() curve = self.curves[0] surface = rs.AddRevSrf(curve, self.axis) rs.DeleteObject(curve) self.curves = [] return surface
def a(): a = (1, 0, 0) b = (5, 0, 5) c = (2, 0, 10) d = (10, 0, 15) curve = rs.AddCurve((a, b, c, d), 5) axis = ((0, 0, 0), (0, 0, 10)) rs.AddRevSrf(curve, axis, 0, 360) rs.AddSphere((0, 0, 12), 3)
def revol(r): if rh.IsCurve(r): return native_ref(rh.AddRevSrf(r, axis, start, end)) elif rh.IsSurface(r) or rh.IsPolysurface(r): out_refs = revolve_borders(r, axis, start, end, True) in_refs = revolve_borders(r, axis, start, end, False) return subtract_refs(single_ref_or_union(out_refs), [native_ref(r) for r in in_refs], shape) else: raise RuntimeError("Can't revolve the shape")
def RevolveSolid(self, first=True, last=True): self.Join() surfaces = [] curve = self.curves[0] surfaces.append(rs.AddRevSrf(curve, self.axis)) rs.DeleteObject(curve) self.curves = [] if first: surfaces.append( self.CreateCircularSurface(self.firstPoint[2], self.firstPoint[0])) if last: surfaces.append( self.CreateCircularSurface(self.currentPoint[2], self.currentPoint[0])) return rs.JoinSurfaces(surfaces, True)
def sweepVolume(crv, tool_id, z_pos): tangent = rs.CurveTangent(crv, rs.CurveParameter(crv, 0)) origin = rs.CurveStartPoint(crv) block = rs.InsertBlock( tool_id, (0,0,0), scale=(1,1,1) ) # rs.DeleteObjects(objs) # pt2 = [origin.X, origin.Y + perp.XAxis[1], origin.Z] pt2 = [origin.X, origin.Y , origin.Z + 1] pt3 = [origin.X + tangent.X, origin.Y + tangent.Y , origin.Z + tangent.Z] ref = [(0,0,0),(0,1,0),(0,0,1)] target = [origin, pt2 ,pt3] block = rs.OrientObject(block, ref, target) objs = rs.ExplodeBlockInstance(block) profile = None for item in objs: if rs.ObjectLayer(item) == 'HULP::C_Toolcontours' or rs.ObjectLayer(item) == 'Hulp::C_Toolcontours': profile = rs.CopyObject(item) rs.DeleteObjects(objs) if not profile: rs.MessageBox('there is no layer named "C_Toolcontours" in block %s' % rs.BlockInstanceName(block)) return False profile = rs.OffsetCurve(profile, rs.CurveAreaCentroid(profile)[0], 0.001, style=1) # rs.MoveObject(profile, (0,0,z_pos)) # rail = obj # rail_crv = rs.coercecurve(rail) # if not rail_crv: return # # cross_sections = [profile] # if not cross_sections: return # cross_sections = [rs.coercecurve(crv) for crv in cross_sections] # # sweep = Rhino.Geometry.SweepOneRail() # sweep.AngleToleranceRadians = scriptcontext.doc.ModelAngleToleranceRadians # sweep.ClosedSweep = True # # sweep.MiterType = 2 # sweep.SweepTolerance = scriptcontext.doc.ModelAbsoluteTolerance # sweep.SetToRoadlikeTop() # breps = sweep.PerformSweep(rail_crv, cross_sections) # for brep in breps: scriptcontext.doc.Objects.AddBrep(brep) # scriptcontext.doc.Views.Redraw() # # # surface_id = rs.LastCreatedObjects() # METHOD1 surface_id = rs.AddSweep1( crv, profile, True ) rs.CapPlanarHoles(surface_id) pt = rs.CurveAreaCentroid(profile)[0] pt2 = (pt.X, pt.Y, pt.Z+1) rev = rs.AddRevSrf( profile, (pt, pt2) ) rs.MoveObject(surface_id, (0,0,z_pos)) rs.MoveObject(rev, (0,0,z_pos)) return [surface_id, rev] rs.UnselectAllObjects() rs.SelectObjects([crv, profile]) result = rs.Command("_-Sweep1 _Enter Style=RoadlikeTop _Enter", False) if result: rs.DeleteObject(profile) surface_id = rs.LastCreatedObjects() rs.CapPlanarHoles(surface_id) rs.DeleteObjects(objs) rs.MoveObject(surface_id, (0,0,z_pos)) return surface_id
def CreateClip(self): milling = False y0 = 0 y1 = self.coreShellHeight y2 = self.coreShellHeight + self.clipLipHeight x0 = self.coreInnerRadius - self.coreSpacerLedgeWidth x1 = self.coreInnerRadius + self.coreShellWidth + self.tolerance x2 = x1 + self.GetDraftDistance(y0, y1) x4 = x2 + self.clipLipThickness x3 = x4 - self.GetDraftDistance(y0, y2) path = Path() path.MoveTo(x0, y1) path.LineTo(x1, y1) path.LineTo(x2, y0) path.LineTo(x4, y0) path.LineTo(x3, y2) path.LineTo(x0, y2) path.CutInFillet(0.6) path.ClosePath() polysurface = path.Revolve() cx1 = x1 cx2 = x2 cy0 = y0 cy1 = y1 armWidth = 8 # cut entry side r = x4 d = x2 - math.sqrt(x2 * x2 - (armWidth / 2) * (armWidth / 2)) e = x2 - d path = PathXZ() path.y = -r path.MoveTo(-12, 0) path.LineTo(-10, 0) path.LineTo(-5, 5) path.CutInFillet(2) path.LineTo(r, 5) path.CutInFillet(2) path.Join() curve = path.curves[0] extrusion = rs.ExtrudeCurveStraight(curve, (0, -r, 0), (0, r, 0)) rs.DeleteObject(curve) extrusion = self.SplitAndKeep(extrusion, polysurface, 1, 0) polysurface = self.SplitAndKeepLargest(polysurface, extrusion) polysurface = rs.JoinSurfaces([polysurface, extrusion], True) # arm flatThickness = 2.5 armInset = 2.5 if milling: flatThickness = 1.5 x2 = -e x0 = x2 - 3.2 x1 = x2 - 2 x3 = x2 + 7 x4 = x2 + 10 x8 = self.coreInnerRadius - armInset x7 = x8 - 2 x6 = x7 - 2 x5 = x6 - 0.1 y0 = -2 - flatThickness y1 = -2 y2 = -2 y3 = -1 y4 = 2 y5 = 0 y6 = 2 y7 = 7 path = PathXZ() path.y = -4 path.MoveTo(x0, y0) path.LineTo(x4, y0) path.LineTo(x8, y3) path.CutInFillet(2) path.LineTo(x7, y4) # path.CutInFillet(0.2) path.LineTo(x6, y4 - 0.2) path.CutInFillet(0.2) path.LineTo(x5, y4 - 1.5) path.LineTo(x3, y2) path.LineTo(x2, y2) path.CutInFillet(2) path.LineTo(x2, y7) path.CutInFillet(0.8) path.LineTo(x0, y7) path.ClosePath() path.CutInFillet(2) path.Shift() path.CutInFillet(2) path.Join() curve = path.curves[0] extrusion = rs.ExtrudeCurveStraight(curve, (0, 0, 0), (0, 8, 0)) end0 = rs.AddPlanarSrf([curve]) end1 = rs.AddPlanarSrf([curve]) rs.MoveObject(end1, (0, 8, 0)) rs.DeleteObject(curve) spring = rs.JoinSurfaces([end0, extrusion, end1], True) polysurface = self.Fuse(polysurface, spring) # cut milling slot y0 = -0.2 y2 = self.coreShellHeight + self.clipLipHeight x1 = self.coreInnerRadius + self.coreShellWidth + self.tolerance x2 = x1 + self.GetDraftDistance(0, self.coreShellHeight) curve = rs.AddLine((x2, 0, y0), (x2, 0, y2)) cut = rs.AddRevSrf(curve, ((0, 0, 0), (0, 0, 1)), 180 - 16, 180 + 16) rs.DeleteObject(curve) box = rs.BoundingBox(cut) xa = box[0][0] ya = box[0][1] xb = box[3][0] yb = box[3][1] side1 = self.CreateRect([(xa, ya, y0), (xa, ya, y2), (-xa, ya, y2), (-xa, ya, y0)]) side1 = self.SplitAndKeep(side1, polysurface, 0, 0) side1 = self.SplitAndKeep(side1, cut, 1, 0) side2 = self.CreateRect([(xb, yb, y0), (xb, yb, y2), (-xb, yb, y2), (-xb, yb, y0)]) side2 = self.SplitAndKeep(side2, polysurface, 0, 0) side2 = self.SplitAndKeep(side2, cut, 1, 0) bottom = self.CreateRect([(xa, ya, y0), (xa, yb, y0), (-15, yb, y0), (-15, ya, y0)]) bottom = self.SplitAndKeep(bottom, cut, 2, 0) cut = rs.JoinSurfaces([cut, side1, side2, bottom], True) cut = self.SplitAndKeepLargest(cut, polysurface) polysurface = self.SplitAndKeepLargest(polysurface, cut) polysurface = rs.JoinSurfaces([polysurface, cut], True) self.clip = polysurface self.CreateLayer("clip", 0xff00ff, polysurface)
def CreateCoreShell(self): x1 = self.coreInnerRadius x0 = x1 - self.coreSpacerLedgeWidth x2 = x1 + self.corePressDepth x3 = x1 + self.coreCoverSlopeDepth x4 = x1 + self.coreShellWidth y0 = 0 y1 = y0 + self.coreCoverSlopeHeight y2 = y1 + self.coreCoverSpace y3 = y2 + self.corePressHeight y5 = y0 + self.coreShellHeight y4 = y5 - self.coreSpacerLedgeHeight path = Path() path.MoveTo(x3, y0) path.LineTo(x4, y0) path.LineTo(x4 - self.GetDraftDistance(y0, y5), y5) path.CutInFillet(0.2) path.LineTo(x0, y5) path.CutInFillet(0.2) path.LineTo(x0, y4) path.LineTo(x1, y4) path.LineTo(x1, y3) path.LineTo(x2, y3) path.LineTo(x2, y2) path.LineTo(x1, y2) path.LineTo(x1, y1) path.ClosePath() polysurface = path.Revolve() # cut the press fit slots required for making molds curve = rs.AddLine((x2, 0, y0), (x2, 0, y2)) cut1 = rs.AddRevSrf(curve, ((0, 0, 0), (0, 0, 1)), -15, 15) rs.DeleteObject(curve) box = rs.BoundingBox(cut1) xa = box[0][0] ya = box[0][1] xb = box[3][0] yb = box[3][1] cut2 = rs.MirrorObject(cut1, (0, -1, 0), (0, 1, 0), True) side1 = self.CreateRect([(xa, ya, y0), (xa, ya, y2), (-xa, ya, y2), (-xa, ya, y0)]) side1s = self.SplitAndKeep(side1, polysurface, [0, 2], 0) side2 = self.CreateRect([(xb, yb, y0), (xb, yb, y2), (-xb, yb, y2), (-xb, yb, y0)]) side2s = self.SplitAndKeep(side2, polysurface, [0, 2], 0) cut1 = rs.JoinSurfaces([cut1, side1s[1], side2s[1]], True) cut2 = rs.JoinSurfaces([cut2, side1s[0], side2s[0]], True) polysurface = self.SplitAndKeep(polysurface, cut1, 0, 0) polysurface = self.SplitAndKeep(polysurface, cut2, 1, 0) polysurface = rs.JoinSurfaces([polysurface, cut1, cut2], True) # cut the USB opening zb = self.coreShellHeight - self.coreSpacerLedgeHeight - self.pcbTopClearance - self.pcbThickness usb = self.ImportObject("usb-opening") rs.MoveObject(usb, (0, 0, zb - 1.3)) usb = self.SplitAndKeep(usb, polysurface, 1) polysurface = self.Cut(polysurface, [usb]) # add "keyed" areas to shell for aligning spacer for a in self.alignmentAngles: key = self.CreateKey(y4 - self.coreSpacerInnerHeight, y4) rs.RotateObject(key, (0, 0, 0), a) polysurface = self.SplitAndKeepLargest(polysurface, key) polysurface = rs.JoinSurfaces([key, polysurface], True) self.coreShell = polysurface self.CreateLayer("shell", 0xff0000, self.coreShell)
fCurves = [] bCurves = [] cylCurves = [] cylsrf = [] _ax = rs.AddLine((-D, 0, 0), (D, 0, 0)) for i in range(0, 9): fCurves.append(rs.AddInterpCurve(fPoints[i], 3)) fCurves[i] = rs.RotateObject(fCurves[i], cPoint, 90) fCurves[i] = rs.MoveObject(fCurves[i], (0, dab[i], zr[i])) fCurves[i] = rs.RotateObject(fCurves[i], cPoint, rangle[i]) bCurves.append(rs.AddInterpCurve(bPoints[i], 3)) bCurves[i] = rs.RotateObject(bCurves[i], cPoint, 90) bCurves[i] = rs.MoveObject(bCurves[i], (0, dab[i], zr[i])) bCurves[i] = rs.RotateObject(bCurves[i], cPoint, rangle[i]) cylCurves.append(rs.AddLine((-D, 0, zr[i]), (D, 0, zr[i]))) cylsrf.append(rs.AddRevSrf(cylCurves[i], _ax, -90, 90)) #Projection of the curve surface pfCurves = [] pbCurves = [] for i in range(9): pfCurves.append(rs.ProjectCurveToSurface(fCurves[i], cylsrf[i], (0, 0, -1))) pbCurves.append(rs.ProjectCurveToSurface(bCurves[i], cylsrf[i], (0, 0, -1))) """for i in range(9): pfCurves.append(rc.Geometry.Curve.ProjectToBrep(fCurves[i], cylsrf[i],(0,0,-1),1)) pbCurves.append(rc.Geometry.Curve.ProjectToBrep(bCurves[i], cylsrf[i],(0,0,-1),1))"""
def revolve_border(border, axis, start, end): res = rh.AddRevSrf(border, axis, start, end) rh.CapPlanarHoles(res) rh.DeleteObject(border) return res
import rhinoscriptsyntax as rs curve = rs.GetObjects("Select curves", 4) axis = ((0, 0, 0), (0, 0, 1)) rs.AddRevSrf(curve, axis, 0, 360)