Make adjustment according to different types of terrain.
import rhinoscriptsyntax as rs import random #for this exercise I need the terrain, so...Please undo it every time #rs.DeleteObjects (rs.AllObjects ()) plane = rs.WorldXYPlane () #Get points from user points = rs.GetPoints ("Please select points locations:") #Make lines clear for me rs.AddPolyline(points) #move points to mesh along the vertical verticalVector = (0,0,1) #select the mesh myMesh = rs.GetObject ("Please select the terrain") projectPoints = rs.ProjectPointToMesh(points, myMesh, verticalVector) #make the moved points visible rs.AddPoints (projectPoints) def myPlatformUnit (point, nextPoint): #make vector to get the size of rectangle myVector = rs.VectorCreate (nextPoint,point) width = myVector [0]*random.uniform(1.3,1.6) height = myVector [1]*random.uniform(1.3,1.6) platformHeight = random.uniform(5,10) midPoint = point #first rectangle origin = point + myVector*-0.5 newPlane = rs.MovePlane (plane, origin) newRectangle1 = rs.AddRectangle (newPlane, width, height) #second rectangle to touch the first one origin = point + myVector*0.5 newPlane = rs.MovePlane (plane, origin) newRectangle2 = rs.AddRectangle (newPlane, width, height) #make 3D plan1 = newRectangle1 topPoint = [point[0], point[1], point[2]+platformHeight] unit1 = rs.ExtrudeCurveStraight (newRectangle1, midPoint, topPoint) rs.CapPlanarHoles (unit1) plan2 = newRectangle2 topPoint = [point[0], point[1], point[2]+platformHeight] unit2 = rs.ExtrudeCurveStraight (newRectangle2, midPoint, topPoint) rs.CapPlanarHoles (unit2) return [unit1, unit2] #make a function to move platform to terrain def movingPlatform (obj): #add vertice point at the bottom of platform unit bbPoints = rs.BoundingBox (obj) bottomPoints = [bbPoints[0],bbPoints[1],bbPoints[2],bbPoints[3]] #move platform unit to terrain along the vertical direction direction = (0,0,1) topz = 0 #make comparison to get the maximum vertical length for point in bottomPoints: projectPoint = rs.ProjectPointToMesh(point, myMesh, direction) if projectPoint: ### added check if point is projected - not all points if platform out of terrain #vector from project point to original point verticalVector = rs.VectorCreate (projectPoint[0],point) #get the moving length.topz = dimension from bottom of platform to terrain z = rs.VectorLength(verticalVector) if z > topz: topz = z #move the platform by using the topz return rs.MoveObject (obj,(0,0,topz)) #make a function to make a pillar def makingPillar (PointA, PointB): #get the top surface of a pillar topSurface = rs.AddCircle (PointA, 0.3) #making 3D for the other three vertices if rs.Distance(PointA, PointB) >0: pillarUnit = rs.ExtrudeCurveStraight (topSurface, PointA, PointB) singlePillar = rs.CapPlanarHoles (pillarUnit) return singlePillar #make the previous function work for every point to make pillars def makingPillars (obj): #add vertice point at the bottom of platform unit bbPoints = rs.BoundingBox (obj) bottomPoints = [bbPoints[0],bbPoints[1],bbPoints[2],bbPoints[3]] #get the direction from moved platform to terrain direction = (0,0,-1) #project bottomPoints to terrain for point in bottomPoints: projectPoint = rs.ProjectPointToMesh(point, myMesh, direction) if projectPoint: ### added check if point is projected - not all points if platform out of terrain myPillars = makingPillar(point, projectPoint[0]) return myPillars #moving Platform and making pillars for i in range (0,len(points)-1): newObj = myPlatformUnit (points[i+1],points[i]) movedPlatform1 = movingPlatform (newObj[0]) makingPillars (movedPlatform1) movedPlatform2 = movingPlatform (newObj[1]) makingPillars (movedPlatform2)