Capstone Project

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)

 

Exercise4

Apply my platform to the existing terrain.

 


import rhinoscriptsyntax as rs
import random

#for this exercise I need the terrain, so...
#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
return unit2

for i in range (0,len(projectPoints)-1):
myPlatformUnit (projectPoints[i+1],projectPoints[i])

Current Problem

Exercise3

 

Use user selected random points to extrude rectangles.

 


import rhinoscriptsyntax as rs
import random

rs.DeleteObjects (rs.AllObjects ())

plane = rs.WorldXYPlane ()

#Get points from user
points = rs.GetPoints ("Please select points locations:")

#make originalRectangle
#def originalRectangle (origin, width, height):
# newPlane = rs.MovePlane (plane, origin)
# newRectangle = rs.AddRectangle (newPlane, width, height)

#originalRectangle (points[0],myWidth,myHeight)

def myPlatformUnit (point, width, height, platformHeight):
midPoint = point
origin = point + myVector*-0.5
newPlane = rs.MovePlane (plane, origin)
newRectangle = rs.AddRectangle (newPlane, width, height)

#make 3D
plan = newRectangle
roof = [origin[0] + myVector[0]/2, origin[1] + myVector[1]/2,platformHeight]
unit = rs.ExtrudeCurveStraight (newRectangle, midPoint, roof)
rs.CapPlanarHoles (unit)

return unit

for i in range (0,len(points)-1):

myVector = rs.VectorCreate (points[i+1],points[i])
myWidth = myVector [0]
myHeight = myVector [1]
platformHeight = random.uniform(20,40)
myPlatformUnit (points[i], myWidth, myHeight, platformHeight)

 

Exercise2

The pictures above show how rectangles are extruded.

 


import rhinoscriptsyntax as rs
import random

rs.DeleteObjects (rs.AllObjects ())

plane = rs.WorldXYPlane ()

 

def myRectangle (origin, width, height):
#origin = rs.CurveStartPoint (platformUnit)
midPoint = [origin[0] + 5, origin[1] + 5,0]
Object = rs.AddPoint (midPoint)

#movePlane
newPlane = rs.MovePlane (plane, origin)
newRectangle = rs.AddRectangle (newPlane, width, height)
#platform = rs.OffsetCurve(platform, midPoint, height)
#newRectangle =
newHeight = random.uniform(2,8)
newMidpoint =rs.MoveObject (Object, [0,0,newHeight])
facade = rs.ExtrudeCurveStraight (newRectangle, midPoint, newMidpoint)
rs.CapPlanarHoles (facade)

points = rs.GetPoints ("Please select points locations:")
for point in points:
myRectangle (point,10,10)

 

Exercise1

Make the basic rectangles in Rhino.

#links to the Rhino Function Library
import rhinoscriptsyntax as rs

#rs.Command ("SelAll Enter Delete")
rs.DeleteObjects (rs.AllObjects() )

#drafts a cardinal point
rs.Command ("Polyline 0,0 5,0 5,5 0,5 0,0")

#drafts a subcardinal point
rs.Command ("Polyline 0,0 10,0 10,3 0,3 0,0")

#drafts a subcardinal point
rs.Command ("Polyline 4,7 -4,7 -4,-7 4,-7 4,7")

#drafts a subcardinal point
rs.Command ("Polyline -6,10 8,10 8,2 -6,2 -6,10")

#drafts a subcardinal point
rs.Command ("Polyline 2,13 13,13 13,5 2,5 2,13")

#drafts a subcardinal point
rs.Command ("Polyline 10,0 10,3 20,3 20,0 10,0")

#drafts a subcardinal point
rs.Command ("Polyline 18,2 18,7 23,7 23,2 18,2")

#drafts a subcardinal point
rs.Command ("Polyline 21,1 21,9 32,9 32,1 21,1")