import rhinoscriptsyntax as rs import random as ran # Clear previous objects allobjs = rs.AllObjects() rs.DeleteObjects(allobjs) # Define basic parameters A = 5 B = A / 3 thick = 0.2 hgt = 2.7 xcol = 2 ycol = 3 levels = 3 f_height = 0.5 f_size = 0.8 center_pt = [A * (xcol - 1) / 2, A * (ycol - 1) / 2, f_height] p_width = A * (xcol - 1) + 2 * B p_length = A * (ycol - 1) + f_size def make_box(insertion=[0, 0, 0], xd=10, yd=10, zd=10): corners = [(0, 0, 0), (xd, 0, 0), (xd, yd, 0), (0, yd, 0), (0, 0, zd), (xd, 0, zd), (xd, yd, zd), (0, yd, zd)] box = rs.AddBox(corners) rs.MoveObject(box, (-xd / 2, -yd / 2, 0)) rs.MoveObject(box, insertion) return box # Foundations def make_foundations(A=5.0, f_size=0.8, f_height=0.5, xcol=2, ycol=3): fns = [] for i in range(xcol): for j in range(ycol): fns.append(make_box([i * A, j * A, 0], f_size, f_size, f_height)) return fns # Columns def make_columns(A=5.0, level=0.7, thick=0.2, hgt=3.0, xcol=2, ycol=3): cls = [] for i in range(xcol): for j in range(ycol): cls.append(make_box([i * A, j * A, level], thick, thick, hgt)) return cls # Random facade generator def make_facade(level, center_pt, p_width, p_length, thick, hgt, window_width=1, window_height=1, gap=0.5): facades = [] # Offset for window height (place windows along the facade at the correct height) window_base = level + thick + 0.1 # Slight offset to ensure windows start after the floor thickness # Front and back facades (along the x-axis) for i in range(int(p_width // (window_width + gap))): x_pos = i * (window_width + gap) - p_width / 2 for j in range(2): # Two windows on opposite sides (front and back) y_pos = (-p_length / 2) if j == 0 else (p_length / 2) if ran.random() > 0.3: # Random chance to create window window = make_box([x_pos + center_pt[0], y_pos + center_pt[1], window_base], window_width, thick, window_height) facades.append(window) # Left and right facades (along the y-axis) for i in range(int(p_length // (window_width + gap))): y_pos = i * (window_width + gap) - p_length / 2 for j in range(2): # Two windows on opposite sides (left and right) x_pos = (-p_width / 2) if j == 0 else (p_width / 2) if ran.random() > 0.3: # Random chance to create window window = make_box([x_pos + center_pt[0], y_pos + center_pt[1], window_base], thick, window_width, window_height) facades.append(window) return facades # Initialize lists f_list = [] c_list = [] p_list = [] fa_list = [] # Loop over levels to create foundations, columns, plates, and facades for i in range(levels): center_pt[2] = f_height + i * (thick + hgt) level = f_height + thick + (i - 1) * (hgt + thick) # Create foundations at the first level if i == 0: f_list = make_foundations(A, f_size, f_height, xcol, ycol) else: # Create columns and add them to the list c_list.extend(make_columns(A, level, thick, hgt, xcol, ycol)) # Create plates (floors) p_list.append(make_box(center_pt, p_width, p_length, thick)) # Create random facades at each level, aligning them with the building sides and floors facade = make_facade(center_pt[2], center_pt, p_width, p_length, thick, hgt, window_width=1, window_height=1.5) fa_list.extend(facade) # Set layers and assign colors rs.AddLayer("foundation") rs.LayerColor("foundation", (20, 220, 90)) rs.ObjectLayer(f_list, "foundation") rs.AddLayer("column") rs.LayerColor("column", (60, 60, 220)) rs.ObjectLayer(c_list, "column") rs.AddLayer("plates") rs.LayerColor("plates", (255, 0, 0)) rs.ObjectLayer(p_list, "plates") rs.AddLayer("facade") rs.LayerColor("facade", (220, 220, 60)) rs.ObjectLayer(fa_list, "facade") # Print the generated lists for debugging purposes print(f_list) print(c_list) print(p_list) print(fa_list)