Rhinoscript: parametric modeling

From KokkugiaWiki

associative modeling through scripting
although we are focusing on developing scripts for generative design processes, we will digress briefly in order to explore the associative logics utilised in parametric models.
rhinocript enables us to quickly develop 3d models that are capable of having all their driving parameters (the variables in the script) as dependent on each other.

polygonal twisting tower
the example below demonstrates how a very simple and short script is capable of generating the set out for a number of different tower geometries. this script hasn't yet linked any of the variables to drive each other. Try modifying this script in able to vary the tower height and plan proportionally to each other, and have the angle of rotation also change pending on the number of segments in the polygonal plan.
Image:polygonal-tower_03_s.jpg

Option Explicit
'------------------------------------------------------------------------------
' twisting polygonal tower generator	
' author: rob stuart-smith | 2008 | www.kokkugia.com
'------------------------------------------------------------------------------

Call Main()
Sub Main()

	Dim arrFlrs, i,j
	Dim strFlr, strLine, strFlrSrf
	
	Dim dblRad: dblRad = 10
	Dim intSegs: intSegs = 4
	Dim intFlrs: intFlrs = 20
	Dim dblHeight: dblHeight = 3.5

	Rhino.EnableRedraw False
	For j = 0 To 10
		ReDim arrFlrs(0)
		For i = 0 To intFlrs
			ReDim Preserve arrFlrs(i)
			arrFlrs(i)  = Rhino.AddCircle(Rhino.WorldXYPlane, dblRad)
			Rhino.MoveObject arrFlrs(i), Array(0,0,0), Array(j*dblRad*2.5,0,i*dblHeight)
			Rhino.RotateObject arrFlrs(i), Array(j*dblRad*2.5,0,i*dblHeight), i*10
			Rhino.RebuildCurve arrFlrs(i),1, (intSegs+j)
			strFlr = Rhino.OffsetCurve (arrFlrs(i),Array(j*dblRad*2.5,0,i*dblHeight) , 0.5)
			strFlrSrf = Rhino.AddPlanarSrf (strFlr )
			strLine = Rhino.AddLine (Array(j*dblRad*2.5,0,i*dblHeight),Array(j*dblRad*2.5,0,i*dblHeight-1))
			Rhino.ExtrudeSurface strFlrSrf(0), strLine, True
			Rhino.DeleteObject strFlrSrf(0)
			Rhino.DeleteObject strLine
		Next
		Rhino.AddLoftSrf arrFlrs
		Rhino.DeleteObjects arrFlrs
	Next
	Rhino.EnableRedraw True
End Sub

catenoid script
catenoids are easy to script and are a good example of how some very simple set out geometry can develop relatively sophisticated curvilinear geometries. In this example all the variables are available to the user to input each time the script is run. As in the previous example you could try linking these variables to make some associative relationships, or better still if you master that - try surfacing the catenoid with a different surface for each diamond between the straight lines.
this script heavily depends on using arrays to cycle through the points on the curves. notice how the curves don't connect vertically; points on the bottom connect to points a few steps away on the top curve. in order to script this we must cycle through the arrays of points on the top and bottom. by introducing a step in the top array we can create lines on a lean. we then must run another loop to pick up the points we have not used to create the missing lines.
Image:catenoid_06.jpg

Option Explicit
'------------------------------------------------------------------------------
' catenoid generator	
' author: rob stuart-smith | 2008 | www.kokkugia.com
'------------------------------------------------------------------------------

Call Main()
Sub Main()

	'--declare variables-------------------------------------------------
	Dim strCirc1, strCirc2
	Dim arrPts1, arrPts2
	Dim i
	Dim dblRad1,dblRad2, dblHeight, intVerts
	Dim intStep
	
	'--assign values to the variables-------------------------------------
	intStep = 3
	dblRad1 = Rhino.GetReal ("what is the radius of the top circle?", 5)
	dblRad2 = Rhino.GetReal ("what is the radius of the bottom circle?", 5)
	dblHeight = Rhino.GetReal ("what is the radius of top circle?", 20)
	intVerts = Rhino.GetInteger ("how many vertical elements?", 12)
	
	'--draw the top and bottom profiles-----------------------------------
	strCirc1 = Rhino.AddCircle(Rhino.WorldXYPlane, dblRad1)
	Rhino.MoveObject strCirc1, Array(0,0,0), Array(0,0,dblHeight)
	strCirc2 = Rhino.AddCircle(Rhino.WorldXYPlane, dblRad2)
	
	'--get an array of points on each profile
	arrPts1 = Rhino.DivideCurve(strCirc1,intVerts,False) 
	arrPts2 = Rhino.DivideCurve(strCirc2,intVerts,False) 
	
	'===draw diagonal lines======================================================
	'--first direction(not to the point above but above and a few pts away)
	For i = 0 To Ubound(arrPts1)- intStep
		Rhino.AddLine arrPts1(i+intStep),arrPts2(i)	
		Rhino.AddLine arrPts2(i+intStep),arrPts1(i)
	Next
	'--as the loop above missed a few pts - we then generate the missing lines in that direction
	For i = 1 To intStep 
		Rhino.AddLine arrPts1(intStep - i),arrPts2(Ubound(arrPts2)- i + 1)
		Rhino.AddLine arrPts2(intStep - i),arrPts1(Ubound(arrPts1)- i + 1)
	Next

	
End Sub
Views