import rhinoscriptsyntax as rs import math rs.DeleteObjects(rs.AllObjects()) # Staircase parameters thick = 0.2 # Step thickness s_width = 3.5 # Stair width tt = 0.45 # Tread depth th = 0.18 # Step height steps = 300 # Total number of steps loops = 6 # Number of loops radius = 6 # Radius of the helix height = 30 # Total height of the staircase DC = 80 # Direction change interval P = 40 # Landing interval # Function to create a helical curve def make_helix(radius, height, loops, steps): points = [] for i in range(steps + 1): angle = (360 * loops / steps) * i # Angle in degrees x = radius * math.cos(math.radians(angle)) y = radius * math.sin(math.radians(angle)) z = (height / steps) * i points.append([x, y, z]) return rs.AddInterpCurve(points) # Function to create the staircase def make_curved_podeststair(curve, th=th, tt=tt, steps=steps, thick=thick, s_width=s_width, DC=DC, P=P): pts = [[0, 0, 0]] for i in range(1, steps): if not (i % DC): # Direction change th = -th pts.append([pts[-1][0] + tt, pts[-1][1], pts[-1][2]]) elif not (i % P): # Landing pts.append([pts[-1][0] + s_width, pts[-1][1], pts[-1][2]]) pts.append([pts[-1][0] + tt, pts[-1][1], pts[-1][2]]) else: # Regular step pts.append([pts[-1][0], pts[-1][1], pts[-1][2] + th]) pts.append([pts[-1][0] + tt, pts[-1][1], pts[-1][2]]) if th < 0: # Final adjustment for downward step pts.append([pts[-1][0], pts[-1][1], pts[-1][2] + th]) # Create the closed polyline for the step outline return_list = [] for i in range(-1, -len(pts), -2): return_list.append([pts[i][0], pts[i][1], pts[i][2] - thick]) pts.extend(return_list) pts.append([pts[0][0], pts[0][1], pts[0][2] - thick]) pts.append(pts[0]) s_outline = rs.AddPolyline(pts) path = rs.AddLine(pts[0], [pts[0][0], pts[0][1] + s_width, pts[0][2]]) shadow = rs.AddLine(pts[0], [return_list[0][0], return_list[0][1], pts[0][2]]) s_surf = rs.AddPlanarSrf(s_outline) rs.Command("_Flow _selID {} _Enter _selID {} _selID {} _Enter".format(s_surf[0], shadow, curve), False) profile = rs.FirstObject() stair = rs.OffsetSurface(profile, s_width / 4, both_sides=True, create_solid=True) rs.DeleteObjects([s_surf[0], shadow, curve, path, s_outline, profile]) return stair # Disable redraw for better performance rs.EnableRedraw(False) # Create the helical curve curve = make_helix(radius, height, loops, steps) # Create the staircase along the helical curve staircase = make_curved_podeststair(curve, th=th, tt=tt, steps=steps, thick=thick, s_width=s_width, DC=DC, P=P) rs.EnableRedraw(True)