import rhinoscriptsyntax as rs rs.EnableRedraw(False) # Clear all existing objects allobjs = rs.AllObjects() rs.DeleteObjects(allobjs) ### Stair parameters s_width = 1.2 # Stair total width pod_l = 1.8 # Landing depth tt = 0.3 # Step depth th = 0.17 # Step rise thick = 0.19 # Stair thickness ### Rectangular spiral parameters turns = 10 # Number of turns start_length = 20 # Starting length of the rectangle ### Function to create a clean rectangular spiral def create_rectangular_spiral(turns, start_length): pts = [] # Points for the spiral x, y = 0, 0 # Starting point current_length = start_length # Initial rectangle size for t in range(turns): # Create a rectangle for the current turn rect = [ [x, y, 0], # Bottom-left corner [x + current_length, y, 0], # Bottom-right corner [x + current_length, y + current_length, 0], # Top-right corner [x, y + current_length, 0], # Top-left corner [x, y, 0] # Back to Bottom-left corner ] # Add the rectangle points to the list pts.extend(rect[:-1]) # Avoid duplicating the starting point # Shrink the rectangle x += 1 # Move x inward y += 1 # Move y inward current_length -= 2 # Decrease size symmetrically # Stop if the rectangle becomes too small if current_length <= 0: break # Create the polyline from the points return rs.AddPolyline(pts) # Usage example rect_spiral = create_rectangular_spiral(turns=20, start_length=10) ### Function to generate the stairs along the curve def make_curved_podeststair(curve, th=th, tt=tt, steps=40, thick=thick, s_width=s_width, pod_l=s_width/2, DC=12, P=12, An=0): pts = [[0, 0, 0]] if th < 0 and An == 0: An = 0.3 steps -= 1 for i in range(1, steps + 1): if not (i % DC): # Direction change pts.append([pts[-1][0], pts[-1][1], pts[-1][2] + th]) pts.append([pts[-1][0] + tt, pts[-1][1], pts[-1][2]]) pts.append([pts[-1][0] + pod_l, pts[-1][1], pts[-1][2]]) pts.append(pts[-1]) pts.append([pts[-1][0] + tt, pts[-1][1], pts[-1][2]]) th = -th elif i == 1: # First landing if An > 0: pts.append([pts[-1][0] + An, pts[-1][1], pts[-1][2]]) pts.append([pts[-1][0], pts[-1][1], pts[-1][2] + th]) pts.append([pts[-1][0] + tt, pts[-1][1], pts[-1][2]]) elif i == steps: # Last landing pts.append([pts[-1][0], pts[-1][1], pts[-1][2] + th]) pts.append([pts[-1][0] + tt, pts[-1][1], pts[-1][2]]) elif not (i % P): # Podest pts.append([pts[-1][0], pts[-1][1], pts[-1][2] + th]) pts.append([pts[-1][0] + tt, pts[-1][1], pts[-1][2]]) pts.append([pts[-1][0] + pod_l, pts[-1][1], pts[-1][2]]) pts.append([pts[-1][0] + tt, pts[-1][1], pts[-1][2]]) else: # Regular steps 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: # Stair ends downward pts.append([pts[-1][0], pts[-1][1], pts[-1][2] + th]) 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) if An > 0: pts.append([pts[1][0] - tt, pts[1][1], pts[1][2] - thick]) 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 / 2, 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 / 2, both_sides=True, create_solid=True) rs.DeleteObjects([s_surf[0], shadow, path, s_outline, profile]) return stair ### Create rectangular spiral curve = create_rectangular_spiral(turns, start_length) len_c = rs.CurveLength(curve) An = 0 P = 10 mods = (len_c + An) / (P * tt + pod_l + tt) steps = int(mods * P) + 1 ### Generate the stairs along the spiral curve make_curved_podeststair(curve, steps=steps, pod_l=pod_l, DC=steps + 1, P=P, An=An) ### Add supports for the stairs i = 1 len_fromstart = An + P * tt + pod_l / 2 num_pipes = int(len_c / (P * tt + pod_l + tt)) while len_fromstart <= len_c: point = rs.CurveArcLengthPoint(curve, len_fromstart) support_line = rs.AddLine(point, [point[0], point[1], i * P * th - thick]) support_pipe = rs.AddPipe(support_line, 0, 0.5) i += 1 len_fromstart += P * tt + pod_l + tt rs.EnableRedraw(True)