def makeNget(_srfs): flsrf = rs.JoinSurfaces(_srfs, delete_input=False) pntstr = [] points = rs.SurfacePoints(flsrf) for point in points: pt = (point.X, point.Y) pntstr.append(pt)
def SplitObject(solid, cSrf): preInnerSrf = rs.CopyObject(cSrf) innerSrfs = rs.TrimBrep(preInnerSrf, solid) if not innerSrfs: rs.DeleteObject(preInnerSrf) return [solid] solids = [] solids.append(solid) for srf in innerSrfs: newSolids = [] for obj in solids: splitObjs = rs.SplitBrep(obj, srf, True) if not splitObjs: newSolids.append(obj) else: for sObj in splitObjs: toJoin = [sObj, srf] newSolids.append(rs.JoinSurfaces(toJoin)) rs.DeleteObjects(splitObjs) solids = newSolids rs.DeleteObjects(innerSrfs) return solids
def PlacePolygon(points, layer): if (layer != 1) and (layer != 16): return None path = PathXY() first = True for point in points: if first: first = False path.MoveTo(point[0], point[1]) if len(point) >= 9: path.ArcTo(point[3], point[4], point[6], point[7]) else: if len(point) >= 9: path.LineTo(point[0], point[1]) path.ArcTo(point[3], point[4], point[6], point[7]) else: path.LineTo(point[0], point[1]) path.ClosePath() path.Join() curve = path.curves[0] # curve = rs.AddPolyline(points) extrusion = rs.ExtrudeCurveStraight(curve, (0, 0, 0), (0, 0, 0.1)) top = rs.AddPlanarSrf([curve]) bot = rs.CopyObject(top, (0, 0, 0.1)) object = rs.JoinSurfaces([top, extrusion, bot], True) rs.DeleteObject(curve) ColorAndMove(object, layer) return object
def unroll(self): x = 0 for i in range(len(self.srfList)): g = rs.AddGroup() s, p = rs.UnrollSurface(self.srfList[i], False, self.unrollList[i]) s = rs.JoinSurfaces(s, True) p = rs.MoveObjects(p, [x, self.name * 10, 0]) s = rs.MoveObject(s, [x, self.name * 10, 0]) b = rs.DuplicateSurfaceBorder(s, 1) rs.ObjectLayer(b, "cut") rs.AddObjectsToGroup(b, g) rs.AddObjectsToGroup(p, g) bb = rs.BoundingBox(s) x += fabs(bb[0].X - bb[1].X) + 1 t = rs.AddText( str(self.name) + "-" + str(i), util.averagePt(rs.CurvePoints(b)), 0.3) t = util.makeEngravingFont(t) rs.AddObjectsToGroup(t, g) rs.DeleteObjects(s)
def makeTriangleSrf(self, i): srfList = [] c0 = self.hexShape.cornersPt[i] c1 = self.hexShape.cornersPt[i + 1] p0 = self.hexProjection.cornersPt[i] p1 = self.hexProjection.cornersPt[i + 1] m = self.hexShape.centerPt mp = self.hexProjection.centerPt tm, tmp = self.move2PtInside(m, mp) t = rs.PointAdd(m, (0, 0.6, 0)) tp = util.projectPtOnSrf(self.hexProjection.attractorPt, self.hexProjection.targetSrf, t) t, tp = self.move2PtInside(t, tp, 0.5) srfList.append(rs.AddSrfPt([t, tm, tmp, tp])) srfList.append(rs.AddSrfPt([c0, m, mp, p0])) srfList.append(rs.AddSrfPt([c0, c1, p1, p0])) srfList.append(rs.AddSrfPt([c1, m, mp, p1])) vt = rs.VectorCreate(c1, p1) rs.RotateObject(srfList[3], c1, 2, vt) return rs.JoinSurfaces(srfList, True)
def CreatePost(self): y0 = 0 y1 = y0 - self.pcbTopClearance y2 = y1 - self.pcbThickness y4 = -self.postHeight y3 = y4 + 0.2 x2 = self.postMateInnerRadius x1 = x2 - self.GetDraftMinimumDistance(y3, y2) x0 = x1 - 0.1 x4 = self.postRadius x3 = x4 - self.GetDraftDistance(y2, y1) x6 = self.postSupportRadius x5 = x6 - self.GetDraftDistance(y1, y0) path = Path() path.MoveTo(x0, y4) path.LineTo(x1, y3) path.LineTo(x2, y2) path.LineTo(x3, y2) path.LineTo(x4, y1) path.LineTo(x5, y1) path.LineTo(x6, y0) post = path.Revolve() cap = path.CreateCircularSurface(y4, x0) return rs.JoinSurfaces([post, cap], True)
def plot_structure(structure): eks = [] for ep in structure.element_properties: elements = structure.element_properties[ep].elements elset = structure.element_properties[ep].elset if elements: eks = elements elif elset: eks = structure.sets[elset].selection sec = structure.element_properties[ep].section t = structure.sections[sec].geometry['t'] for ek in eks: nodes = structure.elements[ek].nodes vert = [structure.nodes[nk].xyz() for nk in nodes] n = scale_vector(normalize_vector(normal_polygon(vert)), t / 2.) n_ = scale_vector(n, -1) v_out = [add_vectors(v, n) for v in vert] v_in = [add_vectors(v, n_) for v in vert] s1 = rs.AddSrfPt(v_out) s2 = rs.AddSrfPt(v_in) srfs = [s1, s2] for i in range(len(v_in)): srf = rs.AddSrfPt( [v_in[-i], v_in[-i - 1], v_out[-i - 1], v_out[-i]]) if srf: srfs.append(srf) rs.JoinSurfaces(srfs, delete_input=True)
def Cut(self, polysurface, holes): for hole in holes: new = rs.SplitBrep(polysurface, hole, True) polysurface = next(x for x in new if rs.IsPolysurface(x)) for n in new: if n is not polysurface: rs.DeleteObject(n) return rs.JoinSurfaces([polysurface] + holes, True)
def makeFace(srfs): srfsJoined = rs.JoinSurfaces(srfs, True) boundaryCrv = rs.DuplicateSurfaceBorder(srfsJoined) srf = rs.AddPlanarSrf(boundaryCrv) rs.DeleteObjects(boundaryCrv) rs.DeleteObject(srfsJoined) rs.DeleteObjects(srfs) return srf
def _irregular_pyramid(pts0, pt1): pts0, pt1 = map(Pt, pts0), Pt(pt1) id = rh.JoinSurfaces([ rh.AddSrfPt((pt00, pt01, pt1)) for pt00, pt01 in zip(pts0, pts0[1:] + [pts0[0]]) ]) rh.CapPlanarHoles(id) return id
def get_brep(self, pts): h = Hull(pts) #print i,h F = [] for f in h.faces: ptlst = map(lambda i: rs.AddPoint(i.v.x, i.v.y, i.v.z), f.vertex) F.append(rs.AddPlanarSrf(rs.AddCurve(ptlst + [ptlst[0]], 1))) brepfacelst = map(lambda c: rs.coercebrep(c), F) brep = rs.JoinSurfaces(brepfacelst) return brep
def _irregular_pyramid_frustum(pts0, pts1): pts0, pts1 = map(Pt, pts0), map(Pt, pts1) id = rh.JoinSurfaces([ rh.AddSrfPt((pt00, pt01, pt11, pt10)) for pt00, pt01, pt10, pt11 in zip(pts0, pts0[1:] + [pts0[0]], pts1, pts1[1:] + [pts1[0]]) ]) rh.CapPlanarHoles(id) return id
def PlacePad(x, y, w, h, r, layer): f = min(w, h) * r * 0.5 curve = CreateRoundedRectangle(x - w / 2.0, y - h / 2.0, x + w / 2.0, y + h / 2.0, 0.0, f) extrusion = rs.ExtrudeCurveStraight(curve, (0, 0, 0), (0, 0, 0.1)) top = rs.AddPlanarSrf([curve]) bot = rs.CopyObject(top, (0, 0, 0.1)) object = rs.JoinSurfaces([top, extrusion, bot], True) rs.DeleteObjects([curve]) ColorAndMove(object, layer) return object
def CreateKey(self, z0, z1): r = self.coreInnerRadius d = self.GetDraftDistance(z0, z1) curve0 = self.CreateKeyCurve(r, z0, d) curve1 = self.CreateKeyCurve(r, z1) surface = rs.AddLoftSrf([curve0, curve1]) rs.DeleteObjects([curve0, curve1]) curve0 = self.CreateKeyCurve(r, z0, d, True) top = rs.AddPlanarSrf([curve0]) rs.DeleteObject(curve0) surface = rs.JoinSurfaces([surface, top], True) return surface
def PlacePCB(curves): curves = rs.JoinCurves(curves, True) surface = rs.AddPlanarSrf(curves) other = rs.CopyObject(surface, (0, 0, -boardThickness)) surfaces = [surface, other] for curve in curves: surfaces.append( rs.ExtrudeCurveStraight(curve, (0, 0, 0), (0, 0, -boardThickness))) rs.DeleteObjects(curves) surface = rs.JoinSurfaces(surfaces, True) index = rs.AddMaterialToObject(surface) rs.MaterialColor(index, (20, 150, 20)) return surface
def join_jigs(self, jigs): start_end = self.create_end_caps(jigs[0].start_corners, rs.VectorReverse(jigs[0].across)) end_end = self.create_end_caps(jigs[len(jigs) - 1].end_corners, jigs[len(jigs) - 1].across) surfaces = [start_end] for i in range(0, len(jigs), 1): surfaces.append(jigs[i].srf) if (i < len(jigs) - 1): surfaces.append(jigs[i].connector) surfaces.append(end_end) surface = rs.JoinSurfaces(surfaces, True) rs.CapPlanarHoles(surface) print rs.IsObjectSolid(surface)
def PlaceRing(x, y, r0, r1, layer): if (layer != 1) and (layer != 16): return None c0 = rs.AddCircle((x, y, 0), r0) c1 = rs.AddCircle((x, y, 0), r1) e0 = rs.ExtrudeCurveStraight(c0, (0, 0, 0), (0, 0, 0.1)) e1 = rs.ExtrudeCurveStraight(c1, (0, 0, 0), (0, 0, 0.1)) curves = [c0, c1] top = rs.AddPlanarSrf(curves) bot = rs.CopyObject(top, (0, 0, 0.1)) object = rs.JoinSurfaces([top, e0, e1, bot], True) rs.DeleteObjects(curves) ColorAndMove(object, layer) return object
def rebuildBrep(obj): srfs = rs.ExplodePolysurfaces(obj) crvs = map(rebuildSrfCrv, srfs) rs.DeleteObjects(srfs) newSrfs = map(rs.AddPlanarSrf, crvs) # newSrfs = rs.AddPlanarSrf(crvs) rs.DeleteObjects(crvs) newbrep = rs.JoinSurfaces(newSrfs, delete_input=True) try: copySourceLayer(newbrep, obj) copySourceData(newbrep, obj) except: pass rs.DeleteObject(obj)
def CreateRadialBar(self, a, r0, r1, w, z0, z1, cap=False): x0 = r0 y0 = -w / 2 x1 = r1 y1 = w / 2 r = w / 2 d = self.GetDraftDistance(z0, z1) curve0 = self.CreateRadial(x0 + d, x1 - d, r - d, z0) curve1 = self.CreateRadial(x0, x1, r, z1) slot = rs.AddLoftSrf([curve0, curve1]) if cap: slot = rs.JoinSurfaces([slot, rs.AddPlanarSrf([curve0])], True) rs.DeleteObjects([curve0, curve1]) slot = rs.RotateObject(slot, (0, 0, 0), a, (0, 0, 1)) return slot
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 create_jig_connectors(self, jigs): for i in range(0, len(jigs) - 1, 1): poly_line_1 = rs.AddPolyline([ jigs[i].end_corners[0], jigs[i + 1].start_corners[1], jigs[i + 1].start_corners[0], jigs[i].end_corners[0] ]) poly_line_2 = rs.AddPolyline([ jigs[i].end_corners[1], jigs[i + 1].start_corners[0], jigs[i].end_corners[0], jigs[i].end_corners[1] ]) poly_line_3 = rs.AddPolyline([ jigs[i].end_corners[1], jigs[i + 1].start_corners[0], jigs[i + 1].start_corners[3], jigs[i].end_corners[1] ]) poly_line_4 = rs.AddPolyline([ jigs[i].end_corners[2], jigs[i + 1].start_corners[3], jigs[i].end_corners[1], jigs[i].end_corners[2] ]) poly_line_5 = rs.AddPolyline([ jigs[i].end_corners[2], jigs[i + 1].start_corners[3], jigs[i + 1].start_corners[2], jigs[i].end_corners[2] ]) poly_line_6 = rs.AddPolyline([ jigs[i].end_corners[3], jigs[i + 1].start_corners[2], jigs[i].end_corners[2], jigs[i].end_corners[3] ]) poly_line_7 = rs.AddPolyline([ jigs[i].end_corners[3], jigs[i + 1].start_corners[2], jigs[i].end_corners[0], jigs[i].end_corners[3] ]) poly_line_8 = rs.AddPolyline([ jigs[i].end_corners[0], jigs[i + 1].start_corners[1], jigs[i + 1].start_corners[2], jigs[i].end_corners[0] ]) srf = rs.JoinSurfaces([ rs.AddPlanarSrf(poly_line_1), rs.AddPlanarSrf(poly_line_2), rs.AddPlanarSrf(poly_line_3), rs.AddPlanarSrf(poly_line_4), rs.AddPlanarSrf(poly_line_5), rs.AddPlanarSrf(poly_line_6), rs.AddPlanarSrf(poly_line_7), rs.AddPlanarSrf(poly_line_8), ], True) jigs[i].addConnector(srf)
def CreatePostHole(self): y0 = 0 y2 = self.coreShellHeight - self.coreSpacerLedgeHeight - self.pcbTopClearance - self.pcbThickness - ( self.coreCoverSlopeHeight + self.coreCoverSpace + self.corePressHeight) y1 = y2 - self.postHeight - 0.5 + self.pcbThickness + self.pcbTopClearance x1 = self.postMateInnerRadius + self.tolerance x0 = x1 - self.GetDraftMinimumDistance(y1, y2) x3 = self.postMateOuterRadius x2 = x3 - self.GetDraftDistance(y0, y2) path = Path() path.MoveTo(x0, y1) path.LineTo(x1, y2) path.LineTo(x2, y2) path.LineTo(x3, y0) post = path.Revolve() cap = path.CreateCircularSurface(y1, x0) return rs.JoinSurfaces([post, cap], True)
def makeSliceSurface(surface, maxAngle): explodedSurfaces = rs.ExplodePolysurfaces(surface) newSurfaces = [] rs.DeleteObject(surface) baseVec = (0, 0, 1) for i in explodedSurfaces: vec = rs.SurfaceNormal(i, [0, 0]) angle = rs.VectorAngle(baseVec, vec) if angle > maxAngle: rs.DeleteObject(i) else: newSurfaces.append(i) joinedSurface = rs.JoinSurfaces(newSurfaces) return joinedSurface
def leaf_gen(self, radius, thickness): edge_pts = [ (0.0, radius, 0.0), (0.0, radius, 2.0 * radius), (- radius * 1.5, radius * 2.0, radius * 5.0), (- radius * 1.5, radius * 2.0, radius * 8.0), (0.0, radius / 2.0, radius * 12.0), (radius, 0.0, radius * 13.0) ] profile_pts_top = [[pt, ((0.5 * thickness) + pt[0], 0.0, pt[2]), (pt[0], -pt[1], pt[2])] for pt in edge_pts[:-1]] profile_pts_bottom = [[(pt[0], -pt[1], pt[2]), ((-0.5 * thickness) + pt[0], 0.0, pt[2]), pt] for pt in edge_pts[:-1]] crvs_top = [rs.AddCurve(pts) for pts in profile_pts_top] crvs_bottom = [rs.AddCurve(pts) for pts in profile_pts_bottom] profile_crvs = [rs.JoinCurves(crvs) for crvs in zip(crvs_top, crvs_bottom)] srf = rs.AddLoftSrf(profile_crvs, end=edge_pts[-1]) cap = rs.AddPlanarSrf([profile_crvs[0]]) result = rs.JoinSurfaces([srf, cap]) return result
import rhinoscriptsyntax as rs srfs = rs.GetObjects('sel srfs') result = rs.JoinSurfaces(srfs, True) print('result is :', result)
def CreateCoreBack(self): tolerance = 0.06 x0 = self.coreInnerRadius - tolerance xn = x0 + self.corePressNub x1 = x0 + self.corePressDepth x2 = x0 + self.coreCoverSlopeDepth xc = x2 - self.coreCoverExtension y1 = 0 y0 = y1 - self.coreCoverExtension y2 = y1 + self.coreCoverSlopeHeight y3 = y2 + self.coreCoverSpace y6 = y3 + self.corePressHeight y4 = y3 + self.corePressNub y5 = y6 - self.corePressNub y7 = self.coreShellHeight - self.coreSpacerLedgeHeight - self.pcbTopClearance - self.pcbThickness y8 = y7 - self.postHeight - 0.1 + self.pcbThickness + self.pcbTopClearance path = Path() path.MoveTo(xc, y0) path.LineTo(x2, y0) path.LineTo(x2, y1) path.Fillet(self.coreCoverExtension) path.LineTo(x0, y2) path.LineTo(x0, y3) path.LineTo(xn, y3) path.LineTo(xn, y4) path.Fillet(self.corePressNub) path.LineTo(xn, y5) path.LineTo(xn, y6) path.LineTo(x0, y6) path.Fillet(self.corePressNub) polysurface = path.RevolveSolid() posts = [] for point in self.postPoints: post = self.CreatePostHole() x = -17 + point[0] y = -17 + point[1] rs.MoveObject(post, (x, y, y6)) posts.append(post) polysurface = self.Cut(polysurface, posts) xb = self.batteryHeight / 2 yb = (self.postPoints[0][1] - 17) - self.postMateOuterRadius - 0.2 xa = -xb ya = yb - self.batteryWidth inset = self.CreateRoundedRectangleCutDown( xa, ya, xb, yb, y7 - self.batteryThickness - self.batterySwell, y6) polysurface = self.Cut(polysurface, [inset]) cap = self.ImportObject("usb-cap") rs.MoveObject(cap, (0, self.usbPcbEdge, y6)) circle = rs.AddCircle3Pt((0, x0, y6), (-x0, 0, y6), (x0, 0, y6)) tube = rs.ExtrudeCurveStraight(circle, (0, 0, y6), (0, 0, y7 + 0.45)) rs.DeleteObject(circle) cap = self.SplitAndKeep(cap, tube, 0) ends = self.SplitAndKeep(tube, cap, [0, 3], 0) cap = rs.JoinSurfaces(ends + [cap], True) cap = self.SplitAndKeep(cap, polysurface, 4) z1 = y6 z0 = z1 - 0.4 b1 = self.CreateRoundCutDown(-2.4, self.usbPcbEdge - 0.9, 1.2, z0, z1) b2 = self.CreateRoundCutDown(2.4, self.usbPcbEdge - 0.9, 1.2, z0, z1) polysurface = self.Cut(polysurface, [cap, b1, b2]) # supports to prevent squishing between top/spacer and back sections = [(-20, 20), (180 - 20, 180 + 20), (180 + 45, 180 + 65), (360 - 65, 360 - 45)] for section in sections: a0 = section[0] * math.pi / 180 a1 = section[1] * math.pi / 180 r1 = self.coreInnerRadius - tolerance r0 = self.pcbRadius - 0.6 support = self.CreateSupportArc(a0, a1, r0, r1, y6, y7) polysurface = self.Cut(polysurface, [support]) self.coreBack = polysurface self.CreateLayer("back", 0x0000ff, self.coreBack)
def CreateCoreSpacer(self): x2 = self.coreInnerRadius - self.tolerance x1 = x2 - self.coreSpacerLedgeWidth - self.coreTopOverlap x0 = x2 - self.coreSpacerCapWidth y1 = self.coreShellHeight - self.coreSpacerLedgeHeight y3 = y1 + self.coreSpacerOuterHeight y4 = y3 + self.coreTopExtension + self.coreSpacerLedgeHeight - self.coreSpacerOuterHeight y0 = y1 - self.coreSpacerInnerHeight y2 = y3 - self.coreSpacerHeight path = Path() path.MoveTo(x0, y2) path.LineTo(x0 + self.GetDraftDistance(y0, y2), y0) path.LineTo(x2, y0) path.LineTo(x2 - self.GetDraftDistance(y0, y1), y1) path.LineTo(x1, y1) path.LineTo(x1, y3) polysurface = path.RevolveSolid() if self.fourPartDesign: slots = [] for i in range(4): a = 180 - 15 + 10 * i r = 17 - 1.8 r0 = r - 0.8 r1 = r + 0.8 slot = self.CreateRadialBar(a, r0, r1, 0.8, y2, y3) slots.append(slot) polysurface = self.Cut(polysurface, slots) bumps = [] for point in self.ledPoints: path = Path() path.MoveTo(0.4, y4) path.LineTo(0.7, y3) bump = path.RevolveSolid(True, False) x = -17 + point[0] y = -17 + point[1] rs.MoveObject(bump, (x, y, 0)) bumps.append(bump) polysurface = self.Cut(polysurface, bumps) else: holes = [] for point in self.ledPoints: path = Path() path.MoveTo(0.4, y3) path.LineTo(0.7, y2) hole = path.Revolve() x = -17 + point[0] y = -17 + point[1] rs.MoveObject(hole, (x, y, 0)) holes.append(hole) polysurface = self.Cut(polysurface, holes) barriers = [] for i in range(6): a = 180 - 25 + 10 * i r = 17 - 1.8 r0 = r - (0.8 - self.tolerance) r1 = r + 1.3 barrier = self.CreateRadialBar(a, r0, r1, 1.0, y2 - self.pcbTopClearance + 0.3, y2, True) barrier = self.SplitAndKeepLargest(barrier, polysurface) barriers.append(barrier) polysurface = self.Cut(polysurface, barriers) posts = [] for point in self.postPoints: post = self.CreatePost() x = -17 + point[0] y = -17 + point[1] rs.MoveObject(post, (x, y, y2)) if y < 0: post = self.SplitAndKeep(post, polysurface, 2) posts.append(post) polysurface = self.Cut(polysurface, posts) # shell alignment key holes for a in self.alignmentAngles: hole = self.CreateKeyHole(y0, y1) rs.RotateObject(hole, (0, 0, 0), a) polysurface = self.SplitAndKeepLargest(polysurface, hole) polysurface = rs.JoinSurfaces([polysurface, hole], True) # support ledge for USB connector z1 = y0 z0 = y0 - self.pcbThickness + self.usbLowerEdge d = self.GetDraftDistance(z0, z1) r1 = x2 r0 = r1 - d circle0 = rs.AddCircle3Pt((-r0, 0, z0), (r0, 0, z0), (0, r0, z0)) edge0 = self.CreateULine(-6, +6, self.usbPcbEdge + d, self.usbPcbEdge + d + 3, z0) curve0 = self.CreateEdgeSupport(edge0, circle0) circle1 = rs.AddCircle3Pt((-r1, 0, z1), (r1, 0, z1), (0, r1, z1)) edge1 = self.CreateULine(-6, +6, self.usbPcbEdge, self.usbPcbEdge + 3, z1) curve1 = self.CreateEdgeSupport(edge1, circle1) support = self.CreateLoftAndCap(curve1, curve0) polysurface = self.Cut(polysurface, [support]) # antenna is 1.2 mm max height, make core-out for 0.2 mm x = 19.558 - 17 y = 2.921 - 17 xa = x - 4.3 / 2 ya = y - 2.2 / 2 xb = x + 4.3 / 2 yb = y + 2.2 / 2 inset = self.CreateRoundedRectangleCutUp(xa, ya, xb, yb, y2, y2 + 0.2) polysurface = self.Cut(polysurface, [inset]) self.coreSpacer = polysurface self.CreateLayer("spacer", 0x00ff00, self.coreSpacer)
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)
#and define the origin for translations moved = [] origin = [0, 0, 0] #Create a couple of Variable for our loop to increment #We use these to keep track of the rows/columns we are on columncount = 0 biggestY = 0 totalX = 0 #Iterate through the baked objects for item in baked: #unroll the surfaces and join them. #delet the ones we don't need unrolltemp = rs.UnrollSurface(item, False) joined = rs.JoinSurfaces(unrolltemp) rs.DeleteObjects(unrolltemp) #Get the bounding box #Bounding Box returns pts we create an empty points list boxpts = [] boxpts = rs.BoundingBox(joined) #Get the distance for the x and y values of the box xdist = rs.Distance(boxpts[0], boxpts[1]) ydist = rs.Distance(boxpts[1], boxpts[2]) #Check to see if the ydist is the biggest in the row #we use this to space our rows if ydist > biggestY: biggestY = ydist #create a bounding polyine #not necessary but help see the border
def Arm(refpt,dir,arrlist): data = ReadJoints(di,fil) O = -1 trim = 1 left = [] upl = [] right = [] upr = [] up = [] down = [] res = Start(refpt,dir,data[0]) dir = res[0] for j in range(len(res[1])): upl.append(rs.VectorAdd(res[1][j],[0,0,-1*trim])) left.append(res[1][j]) for j in range(len(res[2])): upr.append(rs.VectorAdd(res[2][j],[0,0,-1*trim])) right.append(res[2][j]) store = [[left,right],[upl,upr]] srfu = [] srfd = [] cps = StartCap(store) for k in range(len(cps[0])): srfu.append(cps[0][k]) srfd.append(cps[1][k]) info2 = data[0] for i in range(len(arrlist)): trim = trim*fc refpt = rs.VectorAdd(refpt,dir) info = data[arrlist[i]] if i < len(arrlist): res = Elt(refpt,dir,info) res1 = Shift(res,trim) dir = res[0] for j in range(len(res[1])): upl.append(rs.VectorAdd(res[1][j],[0,0,-1*trim])) left.append(res[1][j]) for j in range(len(res[2])): upr.append(rs.VectorAdd(res[2][j],[0,0,-1*trim])) right.append(res[2][j]) store2 = [[res[1],res[2]],[res1[1],res1[2]]] if (len(res[1])> 0 or len(res[2])>0): cps = EltCap(store2,store) for k in range(len(cps[0])): srfu.append(cps[0][k]) srfd.append(cps[1][k]) else: cps = ZeroCap(store2,store) for k in range(len(cps[0])): srfu.append(cps[0][k]) srfd.append(cps[1][k]) store = store2 else: res = Ending(refpt,dir,info) res1 = Shift(res,trim) dir = res[0] for j in range(len(res[1])): upl.append(rs.VectorAdd(res[1][j],[0,0,-1*trim])) left.append(res[1][j]) for j in range(len(res[2])): upr.append(rs.VectorAdd(res[2][j],[0,0,-1*trim])) right.append(res[2][j]) store2 = [[res[1],res[2]],[res1[1],res1[2]]] cps = EndingCap(store2,store) for k in range(len(cps[0])): srfu.append(cps[0][k]) srfd.append(cps[1][k]) store = store2 info2 = info #l1 = rs.AddPolyline(left) #r1 = rs.AddPolyline(right) #l2 = rs.AddPolyline(upl) #r2 = rs.AddPolyline(upr) sidel = StripBuild(left,upl) sider = StripBuild(right,upr) surf["str0","str1","str2","str3"] surf[0] = rs.JoinSurfaces(sidel, True) surf[1] = rs.JoinSurfaces(sider, True) surf[2] = rs.JoinSurfaces(srfu, True) surf[3] = rs.JoinSurfaces(srfd, True) return rs.JoinSurfaces(surf, True)