import rhinoscriptsyntax as rs import math rs.DeleteObjects(rs.AllObjects()) rs.EnableRedraw(False) def generate_twist(width=1000, height=400, height2=800, width2=600, length=1500, heightdif=-150, twist_angle=45, thick=30, thick2=50, frame=150): # 1. Base list of Polylines base_points_1 = [(0, width/2, thick2), (0, width/2, 0), (0, width/2-width, 0), (0, width/2-width, height), (0, width/2, height), (0, width/2, height-thick2)] crv1 = rs.AddPolyline(base_points_1) base_points_2 = [(length-300, width/2, thick2), (length-300, width/2, 0), (length-300, width/2-width, 0), (length-300, width/2-width, height), (length-300, width/2, height), (length-300, width/2, height-thick2)] crv2 = rs.AddPolyline(base_points_2) base_points_3 = [(length, width/2, thick2), (length, width/2, 0), (length, width/2-width, 0), (length, width/2-width, height), (length, width/2, height), (length, width/2, height-thick2)] crv3 = rs.AddPolyline(base_points_3) base_points_4 = [(length*2, width2/2-(width2-2*thick2), height2+heightdif), (length*2, width2/2, height2+heightdif), (length*2, width2/2, 0+heightdif), (length*2, width2/2-width2, 0+heightdif), (length*2, width2/2-width2, height2+heightdif), (length*2, width2/2-width2+thick2, height2+heightdif)] crv4 = rs.AddPolyline(base_points_4) base_points_5 = [(length*2+300, width2/2-(width2-2*thick2), height2+heightdif), (length*2+300, width2/2, height2+heightdif), (length*2+300, width2/2, 0+heightdif), (length*2+300, width2/2-width2, 0+heightdif), (length*2+300, width2/2-width2, height2+heightdif), (length*2+300, width2/2-width2+thick2, height2+heightdif)] crv5 = rs.AddPolyline(base_points_5) base_points_6 = [(length*3, width2/2-(width2-2*thick2), height2+heightdif), (length*3, width2/2, height2+heightdif), (length*3, width2/2, 0+heightdif), (length*3, width2/2-width2, 0+heightdif), (length*3, width2/2-width2, height2+heightdif), (length*3, width2/2-width2+thick2, height2+heightdif)] crv6 = rs.AddPolyline(base_points_6) base_points_M = [(length*3/2, width/2, height/2), (length*3/2, width/2, 0), (length*3/2, width/2-width, 0), (length*3/2, width/2-width, height), (length*3/2, width/2, height), (length*3/2, width/2, height-thick2)] crvM = rs.AddPolyline(base_points_M) rs.RotateObject(crvM, [length*3/2, 0, height/2], twist_angle, (1, 0, 0)) # 2. Loft the twisted form with the adjusted curves loft = rs.AddLoftSrf([crv2, crv3, crvM, crv4, crv5],loft_type=0)[0] # Loft the curves in the desired direction # 3. Extrude the rest of the Surfaces path1 = rs.AddLine([0,0,0], [length,0,0]) path2 = rs.AddLine([length*3,0,0], [length*2,0,0]) srf1 = rs.ExtrudeCurve(crv1, path1) srf2 = rs.ExtrudeCurve(crv6, path2) # 4. ----Fenster,Stuetzen usw. base_points_F_1 = [(0, width/2+thick/2, thick2-thick2/2), (0, width/2+thick/2, height-thick2+thick2/2)] F_crv1 = rs.AddPolyline(base_points_F_1) base_points_F_2 = [(length-300, width/2+thick/2, thick2-thick2/2), (length-300, width/2+thick/2, height-thick2+thick2/2)] F_crv2 = rs.AddPolyline(base_points_F_2) base_points_F_3 = [(length, width/2+thick/2, thick2-thick2/2), (length, width/2+thick/2, height-thick2+thick2/2)] F_crv3 = rs.AddPolyline(base_points_F_3) base_points_F_4 = [(length*2, width2/2-(width2-2*thick2-thick2/2), height2+heightdif+thick/2), (length*2, width2/2-(width2-thick2)-thick2/2, height2+heightdif+thick/2)] F_crv4 = rs.AddPolyline(base_points_F_4) base_points_F_5 = [(length*2+300, width2/2-(width2-2*thick2-thick2/2), height2+heightdif+thick/2), (length*2+300, width2/2-(width2-thick2)-thick2/2, height2+heightdif+thick/2)] F_crv5 = rs.AddPolyline(base_points_F_5) base_points_F_6 = [(length*3, width2/2-(width2-2*thick2-thick2/2), height2+heightdif+thick/2), (length*3, width2/2-(width2-thick2)-thick2/2, height2+heightdif+thick/2)] F_crv6 = rs.AddPolyline(base_points_F_6) base_points_F_M = [(length*3/2, width/2+thick/2, height/2-thick2), (length*3/2, width/2+thick/2, height-thick2+thick2/2)] F_crvM = rs.AddPolyline(base_points_F_M) rs.RotateObject(F_crvM, [length*3/2, 0, height/2], twist_angle, (1, 0, 0)) F_loft = rs.AddLoftSrf([F_crv2, F_crv3, F_crvM, F_crv4, F_crv5],loft_type=0)[0] F_path1 = rs.AddLine([0,0,0], [length-300,0,0]) F_path2 = rs.AddLine([length*3,0,0], [length*2+300,0,0]) F_srf1 = rs.ExtrudeCurve(F_crv1, F_path1) F_srf2 = rs.ExtrudeCurve(F_crv6, F_path2) F_surfaces = [F_loft, F_srf1, F_srf2] F_joined_surface = rs.JoinSurfaces(F_surfaces, True) # Join the surfaces into one # Apply a semi-transparent material if F_joined_surface: material_index = rs.AddMaterialToObject(F_joined_surface) if material_index >= 0: rs.MaterialColor(material_index, (50, 50, 70)) # Set material color (red in this case) rs.MaterialTransparency(material_index, 0.5) # Set transparency (0.0 = opaque, 1.0 = fully transparent) F_contours = rs.AddSrfContourCrvs(F_joined_surface, ([0,0,0], [length*3,0,0]), frame) if F_contours and len(F_contours) > 0: # Group all contours into a single selection rs.SelectObjects(F_contours) # Create a pipe for all selected curves at once rs.Command("Pipe 10 _Enter") # 5. Create contours of surface contours_loft = rs.AddSrfContourCrvs(loft, ([length,0,0], [length*2,0,0]), thick) rs.DeleteObject(loft) contours_srf1 = rs.AddSrfContourCrvs(srf1, ([0,0,0], [length,0,0]), thick) rs.DeleteObject(srf1) contours_srf2 = rs.AddSrfContourCrvs(srf2, ([length*2,0,0], [length*3,0,0]), thick) rs.DeleteObject(srf2) # 6. Extrude contours and OffsetSrf if contours_loft or contours_srf1 or contours_srf2: all_contours = contours_loft + contours_srf1 + contours_srf2 for contour in all_contours: # Extrude the contour as a solid extruded_solid = rs.ExtrudeCurveStraight(contour, (0, 0, 0), (thick - 2, 0, 0)) if extruded_solid: # Select the extruded solid rs.SelectObject(extruded_solid) # For srf1, offset inward if contour in contours_srf1: # Use a negative value for inward offset rs.Command("OffsetSrf {} Corner=sharp Solid=Yes _Enter".format(thick)) # Negative thickness for inward offset # For others, offset outward elif contour in contours_loft or contour in contours_srf2: rs.Command("OffsetSrf {} Corner=sharp Solid=Yes _Enter".format(-thick)) # Positive thickness for outward offset # Deselect after offsetting rs.UnselectObject(extruded_solid) generate_twist()