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 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 createPockets(tool_id, operation, z_pos, obj): if operation == 'Inner contour' or operation == 'Pocket' or operation=='Drill': surface_id = rs.ExtrudeCurveStraight( obj, (0,0,0), (0, 0, MAT_THICKNESS+2) ) rs.CapPlanarHoles(surface_id) rs.MoveObject(surface_id, (0,0,z_pos)) return surface_id
def makeExtrusions(m, obj, material_thickness): tool_id = m.group(1) operation = m.group(2) z_pos = m.group(3) if operation == 'Outer contour': surface_id = rs.ExtrudeCurveStraight( obj, (0,0,0), (0, 0, material_thickness) ) rs.CapPlanarHoles(surface_id) return surface_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 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 extr_bld_flr(): # Extrude all buildings according to NUM_FLOORS attribute multiplied by FLOOR_HEIGHT constant # get all objects in building layer building_objs = rs.ObjectsByLayer(relevant_layers_dict["buildings"]) for building_obj in building_objs: if rs.IsCurve(building_obj) and rs.IsCurveClosed( building_obj ) and rs.CurveArea(building_obj)[0] > MIN_BUILDING_AREA_SQM: crv = rs.coercecurve(building_obj) num_of_floors = rs.GetUserText(building_obj, "NUM_FLOORS") building_height = FLOOR_HEIGHT_M * int(num_of_floors) srf = rs.ExtrudeCurveStraight(crv, (0, 0, 0), (0, 0, building_height)) rs.CapPlanarHoles(srf) rs.ViewDisplayMode(rs.CurrentView(), "Shaded")
def piece(layers, maxScale): curves = [] initialRadii = [] results = [] for i in range(count): initialRadii.append(random.uniform(minScale * maxScale, maxScale)) # outerExtrusions outerExtrusions = [] radii = initialRadii[:] for layer in range(layers): height = layer * layerHeight smooth(radii, smoothAmount) shrink(radii, outerReduce) scale(radii, random.uniform(1 - wiggle, 1 + wiggle)) scale(radii, upwardsShaping(layer / (layers - 1))) vertices = [] for i in range(count): theta = 2 * math.pi * i / count vertices.append((math.sin(theta) * radii[i], math.cos(theta) * radii[i], height)) vertices.append(vertices[0]) curve = rs.AddCurve(vertices, 5) curves.append(curve) if complete: extrusion = rs.ExtrudeCurveStraight(curve, (0, 0, 0), (0, 0, layerHeight)) rs.CapPlanarHoles(extrusion) outerExtrusions.append(extrusion) if not hollow: results.append(extrusion) if hollow: for i in range(shrinkPasses): shrink(radii, innerReduce) # innerExtrusions for layer in range(layers): actualLayer = layers - layer - 1 height = actualLayer * layerHeight smooth(radii, smoothAmount) shrink(radii, innerReduce) vertices = [] for i in range(count): theta = 2 * math.pi * i / count vertices.append((math.sin(theta) * radii[i], math.cos(theta) * radii[i], height)) vertices.append(vertices[0]) curve = rs.AddCurve(vertices, 5) curves.append(curve) if complete: extrusion = rs.ExtrudeCurveStraight(curve, (0, 0, 0), (0, 0, layerHeight)) rs.CapPlanarHoles(extrusion) result = rs.BooleanDifference(outerExtrusions[actualLayer], extrusion) results.append(result) if downwards: radii = initialRadii[:] for layer in range(downwardsLayers): height = -(layer + 1) * layerHeight smooth(radii, smoothAmount) shrink(radii, downwardsReduce) scale(radii, random.uniform(1 - wiggle, 1 + wiggle)) scale(radii, downwardsShaping(layer / (downwardsLayers - 1))) vertices = [] for i in range(count): theta = 2 * math.pi * i / count vertices.append((math.sin(theta) * radii[i], math.cos(theta) * radii[i], height)) vertices.append(vertices[0]) curve = rs.AddCurve(vertices, 5) curves.append(curve) if complete: extrusion = rs.ExtrudeCurveStraight(curve, (0, 0, 0), (0, 0, layerHeight)) rs.CapPlanarHoles(extrusion) outerExtrusions.append(extrusion) if not hollow: results.append(extrusion) if buildScaffolding: scaffoldBase = rs.AddRectangle( (-scaffoldSide / 2, -scaffoldSide / 2, 0), scaffoldSide, scaffoldSide) scaffold = rs.ExtrudeCurveStraight(scaffoldBase, (0, 0, 0), (0, 0, (layers - 1) * layerHeight)) rs.CapPlanarHoles(scaffold) rs.DeleteObject(scaffoldBase) results.append(scaffold) if complete: rs.DeleteObjects(curves) rs.AddObjectsToGroup(results, rs.AddGroup()) return results else: rs.AddObjectsToGroup(curves, rs.AddGroup()) return curves
def RunCommand(is_interactive): global params center = rs.GetPoint(message="Select center point") n = rs.GetInteger(message="Number of teeth", number=params["n"], minimum=4) m = rs.GetReal(message="Gear module", number=params["m"]) pa = rs.GetReal(message="Pressure angle", number=params["pa"], minimum=0, maximum=45) ha = rs.GetReal(message="Helix angle", number=params["ha"], minimum=-45, maximum=45) t = rs.GetReal(message="Thickness", number=params["t"], minimum=0) bool_opts = rs.GetBoolean(message="Output options", items=(("PitchCylinder", "No", "Yes"),), defaults=(params["pc"],)) if None in [center, n, m, pa, ha, t, bool_opts]: return 1 # Cancel pc = bool_opts[0] params["n"] = n params["m"] = m params["pa"] = pa params["ha"] = ha params["t"] = t params["pc"] = pc cplane = rs.ViewCPlane() # Get current CPlane cplane = rs.MovePlane(cplane, center) xform = rs.XformChangeBasis(cplane, rs.WorldXYPlane()) rs.EnableRedraw(False) old_plane = rs.ViewCPlane(plane=rs.WorldXYPlane()) gear = generate_gear_crv(teeth=params["n"], module=params["m"], pressure_angle=params["pa"]) pitch = abs((n * m * pi) / tan(radians(ha))) turns = t / pitch if ha < 0: # Left handed helix turns = -turns centerline = rs.AddLine([0, 0, 0], [0, 0, t]) helix = rs.AddSpiral([0, 0, 0], [0, 0, t], pitch=pitch, turns=turns, radius0=(m * n) / 2) helical_gear_srf = rs.AddSweep2(rails=[centerline, helix], shapes=[gear]) rs.DeleteObjects([centerline, helix, gear]) rs.ViewCPlane(plane=old_plane) rs.TransformObjects(helical_gear_srf, xform) if pc: circle = generate_pitch_circle_crv(teeth=params["n"], module=params["m"]) pitch_cyl_srf = rs.ExtrudeCurveStraight(circle, start_point=[0, 0, 0], end_point=[0, 0, t]) rs.TransformObjects(pitch_cyl_srf, xform) rs.DeleteObject(circle) rs.SelectObjects([helical_gear_srf, pitch_cyl_srf]) else: rs.SelectObjects(helical_gear_srf) rs.EnableRedraw(True) return 0 # Success
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 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)
# if math.sin(12 * (theta - t) + math.pi) > 0: # base -= .02 # else: # base += .02 return base complete = True layerHeight = 2.90 layerCount = 40 baseRadius = 112 phase = (10 / 360) * 2 * math.pi vertexCount = 320 curves = [] for i in range(layerCount): vertices = [] z = layerHeight * i t = map(i, -1, layerCount, 0, 1) #i / (layerCount - 1) radius = baseRadius * layerShape(t) for j in range(vertexCount): theta = map(j, 0, vertexCount, 0, 2 * math.pi) curRadius = radiusShape(theta, t) * radius vertices.append((math.sin(phase + theta) * curRadius, math.cos(phase + theta) * curRadius, z)) vertices.append(vertices[0]) curve = rs.AddCurve(vertices) curves.append(curve) extrusion = rs.ExtrudeCurveStraight(curve, (0, 0, 0), (0, 0, layerHeight)) rs.CapPlanarHoles(extrusion) rs.DeleteObjects(curves)
def makeExtrusions(tool_id, operation, z_pos, obj, material_thickness): if operation == 'Outer contour': surface_id = rs.ExtrudeCurveStraight( obj, (0,0,0), (0, 0, material_thickness) ) rs.CapPlanarHoles(surface_id) return surface_id
def stairHeight(route, width=48, height=120): """ Makes a stair to specified height. input: route(pline), width (num), height(num) returns: Geo """ try: rs.EnableRedraw(False) rs.SimplifyCurve(route) if route is None: print("ERROR: No path selected") return if (rs.UnitSystem() == 2): #if mm maxRiserHeight = 180 thickness = 200 if (rs.UnitSystem() == 4): #if m maxRiserHeight = .180 thickness = .200 if (rs.UnitSystem() == 8): #if in" maxRiserHeight = 7 thickness = 9 negativeBoo = False if (height < 0): #if the stair negativeBoo = True landingEdges = [] landings = [] segments = rs.ExplodeCurves(route) if len(segments) < 1: segments = [rs.CopyObject(route)] landingHeight = [] geometry = [] #Check that all segments are lines for i in range(0, len(segments)): if not (rs.IsLine(segments[i])): print( "ERROR: This function only accepts lines. No arcs or nurb curves." ) rs.DeleteObjects(segments) return #first landing edge norm = rs.VectorRotate(rs.CurveTangent(segments[0], 0), 90, [0, 0, 1]) norm = rs.VectorScale(rs.VectorUnitize(norm), width / 2) side1Pt = rs.VectorAdd(rs.CurveStartPoint(segments[0]), norm) side2Pt = rs.VectorAdd(rs.CurveStartPoint(segments[0]), -norm) landingEdges.append(rs.AddLine(side1Pt, side2Pt)) #middle landing edges for i in range(0, len(segments) - 1): edgeList, landing = rampIntersection(segments[i], segments[i + 1], width) landingEdges.append(edgeList[0]) landingEdges.append(edgeList[1]) landings.append(landing) #last landing edge norm = rs.VectorRotate( rs.CurveTangent(segments[-1], rs.CurveParameter(segments[-1], 1)), 90, [0, 0, 1]) norm = rs.VectorScale(rs.VectorUnitize(norm), width / 2) side1Pt = rs.VectorAdd(rs.CurveEndPoint(segments[-1]), norm) side2Pt = rs.VectorAdd(rs.CurveEndPoint(segments[-1]), -norm) landingEdges.append(rs.AddLine(side1Pt, side2Pt)) #Add risers riserCrvs = [] treadVecs = [] numRisersPerRun = [] numRisers = abs(int(math.ceil(height / maxRiserHeight))) risersSoFar = 0 totalRun = getTotalRun(landingEdges) optTreadDepth = totalRun / (numRisers - 1) #2R+T = 635 riserHeight = height / numRisers if (negativeBoo): curRiserHeight = 0 else: curRiserHeight = riserHeight for i in range(0, len(landingEdges), 2): #find numRisers in each run a = rs.CurveMidPoint(landingEdges[i]) b = rs.CurveMidPoint(landingEdges[i + 1]) runDist = rs.Distance(a, b) numRisersThisRun = int(round((runDist / optTreadDepth), 0)) if (numRisersThisRun == 0): numRisersThisRun = 1 if (i == len(landingEdges) - 2): #if last run, add the rest of the risers numRisersThisRun = numRisers - risersSoFar else: risersSoFar = risersSoFar + numRisersThisRun numRisersPerRun.append(numRisersThisRun) #Create Risers on Plan for i in range(0, len(landingEdges), 2): run = [] a = rs.CurveMidPoint(landingEdges[i]) b = rs.CurveMidPoint(landingEdges[i + 1]) centerStringer = rs.AddLine(a, b) runDist = rs.Distance(a, b) numRisersThisRun = numRisersPerRun[int(i / 2)] #risers in this run tarPts = rs.DivideCurve(centerStringer, numRisersThisRun, create_points=False) rs.DeleteObject(centerStringer) for j in range(0, numRisersThisRun + 1): if (j == 0): treadVecs.append(rs.VectorCreate(tarPts[0], tarPts[1])) transVec = rs.VectorCreate(tarPts[0], tarPts[j]) run.append(rs.CopyObject(landingEdges[i], -transVec)) riserCrvs.append(run) print('Flight {0} has {1} risers: {3}" tall, Treads: {2}" deep'. format( int(i / 2) + 1, numRisersThisRun, rs.VectorLength(treadVecs[int(i / 2)]), riserHeight)) #Move riser edges vertically for i in range(0, len(riserCrvs)): triangles = [] if (negativeBoo): for j in range(0, len(riserCrvs[i]) - 1): #if stairs descending rs.MoveObject( riserCrvs[i][j], rs.VectorAdd([0, 0, curRiserHeight], -treadVecs[i])) riserGeo = rs.ExtrudeCurveStraight(riserCrvs[i][j], [0, 0, 0], [0, 0, riserHeight]) treadGeo = rs.ExtrudeCurveStraight(riserCrvs[i][j], [0, 0, 0], treadVecs[i]) stPt = rs.AddPoint(rs.CurveStartPoint(riserCrvs[i][j])) pt1 = rs.CopyObject( stPt, [0, 0, riserHeight]) #first riser in run pt2 = rs.CopyObject(stPt, treadVecs[i]) #last riser in run triCrv = rs.AddPolyline([stPt, pt1, pt2, stPt]) triangles.append(rs.AddPlanarSrf(triCrv)) geometry.append(riserGeo) #riser geometry.append(treadGeo) #tread curRiserHeight = curRiserHeight + riserHeight rs.MoveObject(riserCrvs[i][j], treadVecs[i]) #cleanup rs.DeleteObject(triCrv) rs.DeleteObject(stPt) rs.DeleteObject(pt1) rs.DeleteObject(pt2) else: for j in range(0, len(riserCrvs[i]) - 1): #if stairs ascend rs.MoveObject(riserCrvs[i][j], [0, 0, curRiserHeight]) stPt = rs.AddPoint(rs.CurveStartPoint(riserCrvs[i][j])) pt1 = rs.CopyObject( stPt, [0, 0, -riserHeight]) #first riser in run pt2 = rs.CopyObject(stPt, -treadVecs[i]) #last riser in run triCrv = rs.AddPolyline([stPt, pt1, pt2, stPt]) triangles.append(rs.AddPlanarSrf(triCrv)) riserGeo = rs.ExtrudeCurveStraight(riserCrvs[i][j], [0, 0, 0], [0, 0, -riserHeight]) treadGeo = rs.ExtrudeCurveStraight(riserCrvs[i][j], [0, 0, 0], -treadVecs[i]) geometry.append(riserGeo) #riser geometry.append(treadGeo) #tread curRiserHeight = curRiserHeight + riserHeight #cleanup rs.DeleteObject(triCrv) rs.DeleteObject(stPt) rs.DeleteObject(pt1) rs.DeleteObject(pt2) #Make Stringer if (negativeBoo): firstStartPt = rs.AddPoint(rs.CurveStartPoint(riserCrvs[i][0])) lastStartPt = rs.AddPoint(rs.CurveStartPoint(riserCrvs[i][-2])) #rs.MoveObject(firstStartPt, [0,0,riserHeight]) #first riser in run rs.MoveObject(lastStartPt, -treadVecs[i]) #last riser in run rs.MoveObject(lastStartPt, [0, 0, riserHeight]) #last riser in run else: firstStartPt = rs.AddPoint(rs.CurveStartPoint(riserCrvs[i][0])) lastStartPt = rs.AddPoint(rs.CurveStartPoint(riserCrvs[i][-2])) rs.MoveObject(firstStartPt, [0, 0, -riserHeight]) #first riser in run rs.MoveObject(lastStartPt, -treadVecs[i]) #last riser in run stringerCrv = rs.AddLine(firstStartPt, lastStartPt) stringerSrf = rs.ExtrudeCurveStraight(stringerCrv, [0, 0, 0], [0, 0, -thickness]) triangles.append(stringerSrf) stringer = makeFace(triangles) stringerVec = rs.VectorCreate(rs.CurveEndPoint(riserCrvs[i][0]), rs.CurveStartPoint(riserCrvs[i][0])) underside = rs.ExtrudeCurveStraight( stringerCrv, rs.CurveStartPoint(riserCrvs[i][0]), rs.CurveEndPoint(riserCrvs[i][0])) geometry.append(rs.MoveObject(underside, [0, 0, -thickness])) geometry.append(rs.CopyObject(stringer, stringerVec)) geometry.append(stringer) #cleanup rs.DeleteObject(firstStartPt) rs.DeleteObject(lastStartPt) rs.DeleteObject(stringerCrv) rs.DeleteObject(stringerSrf) #Move Landings lastLandingHeight = 0 for i in range(0, len(segments) - 1): landingHeight = lastLandingHeight + numRisersPerRun[i] * riserHeight rs.MoveObject(landings[i], [0, 0, landingHeight]) landingTopSrf = rs.AddPlanarSrf(landings[i]) landingBtmSrf = rs.CopyObject(landingTopSrf, [0, 0, -thickness]) geometry.append(landingTopSrf) geometry.append(landingBtmSrf) lastLandingHeight = landingHeight landingEdgesToEx = rs.ExplodeCurves(landings[i]) geometry.append( rs.ExtrudeCurveStraight(landingEdgesToEx[1], [0, 0, 0], [0, 0, -thickness])) geometry.append( rs.ExtrudeCurveStraight(landingEdgesToEx[2], [0, 0, 0], [0, 0, -thickness])) rs.DeleteObjects(landingEdgesToEx) #Create final geometry joinedGeo = rs.JoinSurfaces(geometry, True) holes = rs.DuplicateSurfaceBorder(joinedGeo) cap = rs.AddPlanarSrf(holes) newGeo = rs.ExplodePolysurfaces(joinedGeo, True) for i in cap: newGeo.append(i) FinalGeo = rs.JoinSurfaces(newGeo, True) #cleanup try: rs.DeleteObjects(segments) except: rs.DeleteObject(segments) rs.DeleteObjects(holes) rs.DeleteObjects(landings) rs.DeleteObjects(landingEdges) for i in riserCrvs: rs.DeleteObjects(i) rs.EnableRedraw(True) return FinalGeo except: print "Error" return None
def stairGen(self, sender, e): # Variables and defaults tread = int(self.treadC.Value) * scale riser = int(self.riserC.Value) * scale numSteps = int(self.numStepsC.Value) flip = self.flipC.Checked stairLength = tread * numSteps genStair = self.genStairBool.Checked curveList = [] junkList = [] # get user line for top width of stair rs.EnableRedraw(False) if genStair == False: iteration = rs.ObjectsByName( "GdC9V&^a^rGZZNgiWFH&aTRQLLscu*9AZCmhk8t2!a") if iteration: rs.DeleteObject(iteration) rs.EnableRedraw(True) if genStair == True: # Delete any existing iteration iteration = rs.ObjectsByName( "GdC9V&^a^rGZZNgiWFH&aTRQLLscu*9AZCmhk8t2!a") if iteration: rs.DeleteObject(iteration) topLine = rs.AddLine(line[0], line[1]) topPoint = line[0] stepPoint = topPoint # get perp line - length of stair t = rs.CurveClosestPoint(topLine, topPoint) planeNormal = rs.CurveNormal(topLine) tangent = rs.CurveTangent(topLine, t) curveNormal = rs.VectorCrossProduct(planeNormal, tangent) # Get vector vectorRun = rs.VectorCreate( topPoint, topPoint + curveNormal * tread) # Bool flip direction of stair (add bool option in GUI) if flip == True: vector = rs.VectorReverse(vectorRun) else: vector = vectorRun # loop through number of steps to gen step curve for i in range(numSteps): pt01 = rs.AddPoint(stepPoint) pt02 = rs.CopyObject(pt01, vector) pt03 = rs.CopyObject(pt02, [0, 0, riser*-1]) curve = rs.AddPolyline([pt01, pt02, pt03]) curveList.append(curve) stepPoint = rs.CurveEndPoint(curve) rs.DeleteObjects([pt01, pt02, pt03]) # Extrude stair curve to full width joinedCurve = rs.JoinCurves(curveList) bottomPoint = rs.CopyObject( line[0], [0, 0, (riser*numSteps)*-1]) stairBottom = rs.CurveEndPoint(joinedCurve) curve = rs.AddPolyline([line[0], bottomPoint, stairBottom]) # createhandrail curve and return it handRailCurve = rs.AddCurve([bottomPoint, stairBottom]) curveList.append(curve) joinedCurves = rs.JoinCurves(curveList) stair = rs.ExtrudeCurveStraight(joinedCurves, line[0], line[1]) rs.CapPlanarHoles(stair) # this identifies the generated stair geometry rs.ObjectName( stair, "GdC9V&^a^rGZZNgiWFH&aTRQLLscu*9AZCmhk8t2!a") # clean up leftover geometry junkList.extend([bottomPoint, joinedCurve, joinedCurves, topLine, handRailCurve]) junkList = junkList + curveList rs.DeleteObjects(junkList) rs.EnableRedraw(True)
building_obj) and (rs.CurveArea(building_obj)[0] > MIN_BUILDING_AREA_SQM): crv = rs.coercecurve(building_obj) if rs.PointInPlanarClosedCurve(related_building_pnt, crv): xy_found = True for attr_label, attr_val in zip(attribute_labels_list, attributes_row): rs.SetUserText(building_obj, attr_label, attr_val) if not xy_found: rs.SelectObject(building_obj) print(x_val, y_val, z_val) print(out_loop_counter) ########################################################################################################################################## # Extrude all buildings according to NUM_FLOORS attribute multiplied by FLOOR_HEIGHT constant # get all objects in building layer building_objs = rs.ObjectsByLayer(relevant_layers_dict["buildings"]) for building_obj in building_objs: if rs.IsCurve(building_obj) and rs.IsCurveClosed( building_obj ) and rs.CurveArea(building_obj)[0] > MIN_BUILDING_AREA_SQM: crv = rs.coercecurve(building_obj) num_of_floors = rs.GetUserText(building_obj, "NUM_FLOORS") if num_of_floors == None: pass # building_height = FLOOR_HEIGHT_M * num_of_floors srf = rs.ExtrudeCurveStraight(crv, (0, 0, 0), (0, 0, 20)) rs.CapPlanarHoles(srf) rs.ViewDisplayMode(rs.CurrentView(), "Shaded")
def extrudePolygon(self, height): startPt = self.origin newZ = self.origin[2] + height endPt = [self.origin[0], self.origin[1], newZ] return rs.ExtrudeCurveStraight(self.polygon, startPt, endPt)
def DrawDDARamp(): try: def scale(): system = rs.UnitSystem() if system == 2 or system == 3 or system == 4: scaleFactorDict = {2: 1000, 3: 100, 4: 1} scaleFactor = scaleFactorDict[system] return scaleFactor if system != 2 or system != 3 or system != 4: return None if scale() == None: rs.MessageBox( "This tool is can only be used in mm, cm or m model units") return None Mult = scale() pt00 = rs.GetPoint('Pick insertion point') if pt00: pt01 = rs.CreatePoint(pt00.X, pt00.Y) RampOptions = 'Step Ramp', 'Kerb Ramp', 'Ramp', 'Walkway' RampType = rs.PopupMenu(RampOptions) rs.EnableRedraw(False) if RampType == -1: exit() if RampType == 0: # Step Ramp Curve = rs.AddPolyline([ (pt01), (pt01.X, pt01.Y, (0.190 * Mult)), ((pt01.X + 1.9 * Mult), pt01.Y, pt01.Z), (pt01) ]) Surface = rs.ExtrudeCurveStraight( Curve, (pt01), (pt01.X, (pt01.Y + 1 * Mult), pt01.Z)) rs.CapPlanarHoles(Surface) vector = rs.VectorCreate(pt00, pt01) rs.MoveObject(Surface, vector) rs.DeleteObject(Curve) if RampType == 1: # Kerb Ramp # main ramp portion Curve = rs.AddPolyline([ (pt01), (pt01.X, pt01.Y, (0.190 * Mult)), ((pt01.X + 1.52 * Mult), pt01.Y, pt01.Z), (pt01) ]) Surface = rs.ExtrudeCurveStraight( Curve, (pt01), (pt01.X, (pt01.Y + 1 * Mult), pt01.Z)) rs.CapPlanarHoles(Surface) vector = rs.VectorCreate(pt00, pt01) rs.MoveObject(Surface, vector) rs.DeleteObject(Curve) if RampType == 2: # Ramp Grade = '1:19', '1:18', '1:17', '1:16', '1:15', '1:14' Index = rs.PopupMenu(Grade) GradeNum = [19, 18, 17, 16, 15, 14] if Index == 5: Rise = 9 / (GradeNum[Index]) Curve = rs.AddPolyline([(pt01), (pt01.X, pt01.Y, (Rise * Mult)), ((pt01.X + 9 * Mult), pt01.Y, pt01.Z), (pt01)]) Surface = rs.ExtrudeCurveStraight( Curve, (pt01), (pt01.X, (pt01.Y + 1 * Mult), pt01.Z)) rs.CapPlanarHoles(Surface) vector = rs.VectorCreate(pt00, pt01) rs.MoveObject(Surface, vector) rs.DeleteObject(Curve) elif Index != 5: Rise = 15 / (GradeNum[Index]) Curve = rs.AddPolyline([(pt01), (pt01.X, pt01.Y, (Rise * Mult)), ((pt01.X + 15 * Mult), pt01.Y, pt01.Z), (pt01)]) Surface = rs.ExtrudeCurveStraight( Curve, (pt01), (pt01.X, (pt01.Y + 1 * Mult), pt01.Z)) rs.CapPlanarHoles(Surface) vector = rs.VectorCreate(pt00, pt01) rs.MoveObject(Surface, vector) rs.DeleteObject(Curve) if RampType == 3: # Walkway Grade = '1:33', '1:32', '1:31', '1:30', '1:29', '1:28', '1:27', '1:26', '1:25', '1:24', '1:23', '1:22', '1:21', '1:20' Index = rs.PopupMenu(Grade) GradeNum = [ 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20 ] if Index == 0: Rise = 25 / (GradeNum[Index]) Curve = rs.AddPolyline([(pt01), (pt01.X, pt01.Y, (Rise * Mult)), ((pt01.X + 25 * Mult), pt01.Y, pt01.Z), (pt01)]) Surface = rs.ExtrudeCurveStraight( Curve, (pt01), (pt01.X, (pt01.Y + 1 * Mult), pt01.Z)) rs.CapPlanarHoles(Surface) vector = rs.VectorCreate(pt00, pt01) rs.MoveObject(Surface, vector) rs.DeleteObject(Curve) if Index == 13: Rise = 15 / (GradeNum[Index]) Curve = rs.AddPolyline([(pt01), (pt01.X, pt01.Y, (Rise * Mult)), ((pt01.X + 15 * Mult), pt01.Y, pt01.Z), (pt01)]) Surface = rs.ExtrudeCurveStraight( Curve, (pt01), (pt01.X, (pt01.Y + 1 * Mult), pt01.Z)) rs.CapPlanarHoles(Surface) vector = rs.VectorCreate(pt00, pt01) rs.MoveObject(Surface, vector) rs.DeleteObject(Curve) elif Index != 0 or Index != 13: # Linear interpolation of landing distance - DDA requirement...Srsly? Interp = m.floor(((GradeNum[Index] - 20) * (25 - 15) / (33 - 20)) + 15) Rise = Interp / (GradeNum[Index]) Curve = rs.AddPolyline([(pt01), (pt01.X, pt01.Y, (Rise * Mult)), ((pt01.X + Interp * Mult), pt01.Y, pt01.Z), (pt01)]) Surface = rs.ExtrudeCurveStraight( Curve, (pt01), (pt01.X, (pt01.Y + 1 * Mult), pt01.Z)) rs.CapPlanarHoles(Surface) vector = rs.VectorCreate(pt00, pt01) rs.MoveObject(Surface, vector) rs.DeleteObject(Curve) rs.EnableRedraw(True) except: print("Failed to execute") rs.EnableRedraw(True) return