import rhinoscriptsyntax as rs import math # Delete all objects and start from scratch rs.DeleteObjects(rs.AllObjects()) def create_scallop_shell(): if not rs.IsLayer("loft"): rs.AddLayer("loft") if not rs.IsLayer("pipes"): rs.AddLayer("pipes") # Shell parameters shell_height = 10 # height of the shell optimal = 10 shell_width = 12 # width of the shell optimal = 12 curvature_height = 2 # Vertical curvature of the shell rib_count = 30 # Number of radial ribs skip_count = 6 # Number of ribs to skip on each side pipe_radius_2 = 0.15 pipe_radius_1 = 0.05 # Define scaling factors for the profile curve, for soft coding scale_x1 = 0.2 # first point position horizontally optimal = 0.2 scale_y1 = 0.2 # first point position vertically optimal = 0.2 scale_x2 = 0.5 # middle point position horizontally opt = 0.5 scale_y2 = 0.5 # middle point position vertically opt=0.5 scale_x3 = 0.8 # points close to shell edges, width wise opt = 0.8 scale_y3 = 0.4 # points close to shell edges, height wise opt = 0.4 scale_x4 = 0.15 # point near the origin, width wise opt=0.15 scale_y4 = 0.15 # point near the origin, height wise opt = 0.15 # Outer profile curve outer_profile_points = [ (0, 0, 0), (shell_width * scale_x1, -shell_height * scale_y1), (shell_width * scale_x2, -shell_height * scale_y2), (shell_width * scale_x3, -shell_height * scale_y3), (shell_width, 0), (shell_width * scale_x3, shell_height * scale_y3), (shell_width * scale_x2, shell_height * scale_y2), (shell_width * scale_x4, shell_height * scale_y4), (0, 0, 0) ] outer_profile_curve = rs.AddInterpCurve(outer_profile_points) # Create only the middle ribs, skipping the first and last 6 rib_curves = [] for i in range(skip_count, rib_count - skip_count + 1): t = i / rib_count rib_point = rs.EvaluateCurve(outer_profile_curve, rs.CurveParameter(outer_profile_curve, t)) rib_points = [] for j in range(20): # Create points along each rib factor = j / 19 x = rib_point[0] * factor y = rib_point[1] * factor z = curvature_height * math.sin(math.pi * factor) * (1 - factor**0.5) # Smooth transition rib_points.append((x, y, z)) rib_curve = rs.AddInterpCurve(rib_points) rib_curves.append(rib_curve) # Create pipes and add to "pipes" layer pipe = rs.AddPipe(rib_curve, [0, 1], [pipe_radius_1, pipe_radius_2], cap=2) if pipe: rs.ObjectColor(pipe, (255, 255, 0)) rs.ObjectLayer(pipe, "pipes") # Create loft surfaces and add to "loft" layer if len(rib_curves) >= 6: loft_curves = rib_curves[:6] loft_surface = rs.AddLoftSrf(loft_curves) if loft_surface: rs.ObjectColor(loft_surface[0], (0, 0, 255)) rs.ObjectLayer(loft_surface[0], "loft") if len(rib_curves) > 18: loft_curves = rib_curves[5:19] loft_surface = rs.AddLoftSrf(loft_curves) if loft_surface: rs.ObjectColor(loft_surface[0], (0, 0, 255)) rs.ObjectLayer(loft_surface[0], "loft") # create loft vorne links last_line_left = rs.AddLine((0, 0, 0), (3.830, -3.417, 0)) if rib_curves: first_rib = rib_curves[0] loft_surface_left = rs.AddLoftSrf([last_line_left, first_rib]) if loft_surface_left: rs.ObjectColor(loft_surface_left[0], (255, 0, 0)) # Red color for visibility rs.ObjectLayer(loft_surface_left[0], "loft") # Add line and create a loft on the right side last_line_right = rs.AddLine((0, 0, 0), (3.686, 3.318, 0)) if rib_curves: last_rib = rib_curves[-1] loft_surface_right = rs.AddLoftSrf([last_line_right, last_rib]) if loft_surface_right: rs.ObjectColor(loft_surface_right[0], (255, 0, 0)) # Green color for visibility rs.ObjectLayer(loft_surface_right[0], "loft") # Add polyline for side things polyline_points = [(0.574, -0.513, 0), (0.562, -2.039, 0), (2.368, -2.115, 0), (0.574, -0.513, 0)] polyline_1 = rs.AddPolyline(polyline_points) polyline_points_2 = [(0.583, 0.524, 0), (0.562, 2.043, 0), (2.368, 2.119, 0), (0.583, 0.524, 0)] polyline_2 = rs.AddPolyline(polyline_points_2) # Extrusion height height = 0.3 extrusion_vector = (0, 0, height) # Extrude and make solids if polyline_1: extruded_polyline_1 = rs.ExtrudeCurveStraight(polyline_1, (0, 0, 0), extrusion_vector) if extruded_polyline_1: rs.CapPlanarHoles(extruded_polyline_1) if polyline_2: extruded_polyline_2 = rs.ExtrudeCurveStraight(polyline_2, (0, 0, 0), extrusion_vector) if extruded_polyline_2: rs.CapPlanarHoles(extruded_polyline_2) # add rips as lines line_1 = rs.AddLine((1.010, 0.909, 0.22), (1.010, 2.062, 0.22)) line_2 = rs.AddLine((1.597, 2.086, 0.22), (1.595, 1.436, 0.22)) line_3 = rs.AddLine((1.010, -0.902, 0.22), (1.010, -2.057, 0.22)) line_4 = rs.AddLine((1.597, -1.426, 0.22), (1.595, -2.082, 0.22)) # Pipe radius pipe_radius_12 = 0.15 pipe_radius_11 = 0.1 # Create pipes if line_1: pipe_1 = rs.AddPipe(line_1, [0, 1], [pipe_radius_11, pipe_radius_12], cap=1) if line_2: pipe_2 = rs.AddPipe(line_2, [0, 1], [pipe_radius_11, pipe_radius_12],cap=1) if line_3: pipe_3 = rs.AddPipe(line_3, [0, 1], [pipe_radius_11, pipe_radius_12],cap=1) if line_4: pipe_4 = rs.AddPipe(line_4, [0, 1], [pipe_radius_11, pipe_radius_12], cap=1) # Run the script create_scallop_shell()