import rhinoscriptsyntax as rs import random as ran import math #cleanup and start from scratch rs.DeleteObjects(rs.AllObjects()) rs.EnableRedraw(False) ################################################################################ #variables ################################################################################ #unit: meters #variables for baseline (arc sequence) three_dim=0 #switch for three dimensional bridge: if 0, the bridge is flat, if 1, the bridge goes up and down z_var=5 #how much the z value varies if the bridge is three dimensional (range from 0 meters to x meters) turns=5 #how many times whole pavillon way curves/turns arc_length=20 #how long an arc is (combination of those two are up_downs=arc_length/2 #how many ups and downs there are in the pavillon way (not two many), in relation to the length of the curve/number of turns three_dim=1 #on/of switch for the three dimensional pathway (if it is zero, the bridge is flat, if it is one, the bridge is three dimensional) #general variables width=3 #width of bridge, also distance between columns (so the pavillons are square(ish)) thick=0.2 #thickness of bridge part #variables for columns hgt=3 #height of columns hel_th=0.04 #helix radius hel_pip=0.07 #helix radius for piping #variables for domes hgt_dome=2.5 #dome height (from height to peak) side_arc_hgt=1 #arc on the side of the pavilion height base_th=0.2 #radius for base (start) base_hgt=0.3 #total height for base #vorgehensweise #thickness linien im oberen teil #thickness dome oberer teil #surface fuer domes: mit sweep2 - gitter dann mit pull #sweep dome lines to surface (4 open surfaces) #draw pattern on floor - pull pattern onto surfaces #vor flow (dinge die veraendert werden und distorted werden muessen: boegen unter der bruecke (und deren linie), basis, pavilion (inkl. linien fuer flow) #nach flow (dinge die nicht veraendert werden duerfen und nicht distorted sein sollen): columns unter der bruecke, columns ueber der bruecke, alles inklusive basis #erst spaeter pipen: also vorher linien machen und pullen, dann pipen oder sweepen #vorher aufpassen wie die pavillons erstellt werden (sie muessen sich ans gelaende anpassen koennen) #lists pts=[] #list for all the points for the bridge inner_pts=[] #list for the points on the inner curve outer_pts=[] #list for the points on the outer curve cls=[] #list for columns bridge=[] #list for bridge domes=[] #list for domes flow_obj=[] #list for all objects that are subjected to the flow command #functions def make_box(insertion=[0,0,0],xsize=0.5,ysize=10,zsize=0.2): corners=[[0,0,0],[xsize,0,0],[xsize,ysize,0],[0,ysize,0], [0,0,zsize],[xsize,0,zsize],[xsize,ysize,zsize],[0,ysize,zsize]] box=rs.AddBox(corners) #rs.MoveObject(box,[-xsize/2,0,0]) rs.MoveObject(box,insertion) return(box) def create_baselines(): global help_line global length global line global line_offs #same curve as line, just offsetted (so you can create the inner and the outer curve) points=[] #points for creating a polyline with the arc command #pts_later=[] #points after rebuilding for i in range(turns): points.append([0,i*arc_length,0]) cmd="-_Polyline" for i in range(len(points)): cmd += " {},{},{} Mode=Arc".format(0,points[i][1],0) cmd+=" _Enter" rs.Command(cmd) #move some points of the line up a bit to create a 3d walkway line=rs.FirstObject() rs.RebuildCurve(line,degree=3,point_count=turns*3) #pts_later.extend(rs.CurvePoints(line)) #keep for later if three_dim==1: rs.EnableObjectGrips(line,enable=True) #you cannot move the object grips with the moveobject command, you have to reassign a whole set of new grips grips=rs.ObjectGripLocations(line) #list for grips for i in range(int(up_downs)): index=ran.choice(range(len(grips))) #index for grips (random choice) ran_move=ran.uniform(0.7,z_var) move_vector=[0,0,ran_move] #vector for moving the grips up new_location=rs.PointAdd(grips[index],move_vector) rs.ObjectGripLocation(line,index,new_location) #move grip to new location rs.EnableObjectGrips(line,enable=False) else: print ("three_dim was set to zero, so the bridge is flat") length=rs.CurveLength(line) help_line=rs.AddLine([0,0,0],[0,length,0]) line_offs=rs.OffsetCurve(line,[1,0,0],width) def column_base(pt): #pt is the insertion point circle=rs.AddCircle(pt,base_th) circle2=rs.MoveObject(rs.ScaleObject(circle,pt,[1.2,1.2,0],copy=True),[0,0,base_hgt/4]) crcls=[] crcls.append(circle) crcls.append(circle2) crcls.append(rs.CopyObject(circle,[0,0,base_hgt/2])) crcls.append(rs.CopyObject(circle2,[0,0,base_hgt/2])) crcls.append(rs.CopyObject(circle,[0,0,base_hgt])) srf=rs.AddLoftSrf(crcls) rs.CapPlanarHoles(srf) def column(pt): plane=rs.AddPlaneSurface(rs.WorldXYPlane(),100,100) rs.ScaleObject(plane,[50,50,0],[5,5,0]) spirals=[] #list for base spirals #rs.AddLine(pt,[pt[0],pt[1],hgt]) #check height sp1=rs.AddSpiral([pt[0],pt[1],hgt],pt,1.5,8,hel_th) sp2=rs.RotateObject(sp1,pt,120,copy=True) sp3=rs.RotateObject(sp2,pt,120,copy=True) spirals.extend([sp1,sp2,sp3]) for sp in spirals: pipe=rs.AddPipe(sp,parameters=[0,1],radii=[hel_pip,hel_pip],cap=1) if pipe: cls.append(pipe) for cl in cls: if rs.IsBrep(cl): #check if the object is a brep (otherwise it will not split result=rs.SplitBrep(cl,plane,delete_input=True) #split columns in half (to delete lower part) if result: cls.extend(result) for obj in cls: if rs.IsObject(obj): bbox=rs.BoundingBox(obj) min_z=min(pt[2] for pt in bbox) if min_z < (-thick-0.01): #check if parts of cls are below 0 rs.DeleteObject(obj) #delete parts below zero rs.DeleteObject(plane) return [obj for obj in cls if rs.IsObject(obj)] #checks all the objects if they are an object #some part of the cls list are not object, i have not found the reason why #it was too complicated to create a helix with a specific height (mathematical function required)- so i cut the columns in half at the XY Plane def dome(): dgs=[] #list with lines secs=[] #list with intersections arcs=[] #list with arcs for the sides for i in range(len(inner_pts)-1): #make lines for the center of the pavilion l1=rs.AddLine(inner_pts[i],outer_pts[i+1]) l2=rs.AddLine(inner_pts[i+1],outer_pts[i]) arc_point_inner=rs.VectorDivide(rs.VectorAdd(inner_pts[i],inner_pts[i+1]),2) arc_point_outer=rs.VectorDivide(rs.VectorAdd(outer_pts[i],outer_pts[i+1]),2) arc_point_inner[2]=arc_point_inner[2]+side_arc_hgt arc_point_outer[2]=arc_point_outer[2]+side_arc_hgt a1=rs.AddArc3Pt(inner_pts[i],inner_pts[i+1],arc_point_inner) a2=rs.AddArc3Pt(outer_pts[i],outer_pts[i+1],arc_point_outer) intersection=rs.CurveCurveIntersection(l1, l2) dgs.append(l1) dgs.append(l2) arcs.append(a1) arcs.append(a2) for inter in intersection: if len(inter)>1: #curvecurveintersection produces not just the coordinates: make sure it produces more than 0 point=inter[1] #get the coordinates of the intersection points secs.append(point) rs.MoveObjects(dgs,[0,0,hgt]) #move all lines to correct position rs.MoveObjects(arcs,[0,0,hgt]) for i in secs: rs.AddLine([i[0],i[1],hgt],[i[0],i[1],hgt+hgt_dome]) def create_base(): base=make_box(xsize=width,ysize=length,zsize=-thick) flow_obj.append(base) #fuer bodenmuster interp points on surface def flow(): for i in range(len(flow_obj)): rs.Command("_Flow _SelID {} _Enter Roadlike=Yes Copy=No _SelID {} _SelID {} 0,0,0 0,0,1 _Enter".format(flow_obj[i],help_line,line),False) def make_bridge(): create_baselines() create_base() flow() #derived values for bridge num_dec=length/width #length divided by width gets the total number (with some decimal points) num_tot=int(num_dec) #round down the number (so i get an integer) pav_length=length/num_dec #divide length by num_tot so i get a new length inner_pts.extend(rs.DivideCurve(line_offs,num_tot,create_points=True)) outer_pts.extend(rs.DivideCurve(line,num_tot,create_points=True)) pts=inner_pts+outer_pts global block_column cl=column(pt=[0,0,0]) #bas=column_base(pt=[0,0,0]) block_column=rs.AddBlock(cl,[0,0,0],"block_column") rs.DeleteObjects(cl) #block_base=rs.AddBlock(bas,[0,0,0],"block_base") #rs.DeleteObjects(bas) for pt in pts: rs.InsertBlock(block_column,pt,scale=(1,1,1),angle_degrees=0,rotation_normal=(0,0,1)) #rs.InsertBlock(block_base,pt,scale=(1,1,1),angle_degrees=0,rotation_normal=(0,0,1)) #dome() make_bridge() """ #layers rs.AddLayer("bridge") rs.LayerColor("bridge", (255,255,0)) rs.ObjectLayer(bridge,"bridge") rs.AddLayer("domes") rs.LayerColor("domes", (0,255,255)) rs.ObjectLayer(domes,"domes") rs.AddLayer("columns") rs.LayerColor("columns", (255,255,255)) rs.ObjectLayer(cls,"columns") """ #cleanup rs.Command("_SelCrv _Enter") crvs=rs.SelectedObjects() rs.DeleteObjects(crvs) rs.Command("_Selpt _Enter") too_many_points=rs.SelectedObjects() rs.DeleteObjects(too_many_points) rs.EnableRedraw(True)