Here are some rhinoscripts those will be exercised in Digital Crafting Workshop – HexaPanels @ UPH Architecture.
Rhinoscript exercise #1 :
In this script exercise #1, we try to customize a planar modular system which modulated from a polygon. The customization created from a distance logic between each individual centroid of the module and a curve -as the attractor; which in the next step, the value of the distances will be used as an input to offset curve of a planar module.
Option Explicit 'Script written by <Dani Hermawan - www.formologix.com > <www.formo.co> 'Script version Friday, 15 July 2011 13:32:45 Call Main() Sub Main() Dim arrCrvs01 : arrCrvs01 = Rhino.GetObjects("Select Curves to offset") Dim arrPtCent Dim crv01 Dim dblDist Dim crvAtt : crvAtt=Rhino.GetObject("Select Curve to evaluate") Dim arrEvaPt Dim dblParam Dim crv02 Dim arrCrvs02 'for loop-ing to do repetitive procedure For Each crv01 In arrCrvs01 arrPtCent= Rhino.CurveAreaCentroid(crv01) 'get the centroid of the curve 'dblParam=Rhino.CurveClosestPoint(crvAtt, arrPtCent(0)) 'get parameter of the closest point on a curve Rhino.Print "Curve parameter: " & CStr(dblParam) arrEvaPt=Rhino.CurveEvaluate(crvAtt,dblParam,1) 'get coordinate of closest point on a curve dblDist=Rhino.Distance(arrEvaPt(0),arrPtCent(0)) 'analyse the distance for distance logic dblDist=dblDist/10 crv02=Rhino.OffsetCurve(crv01,arrPtCent(0),dblDist) 'offseting curve according to distance logic arrCrvs02 = Array(crv01, crv02(0)) If Rhino.IsCurveClosed(crv02(0)) Then Rhino.AddLoftSrf arrCrvs02 'create lofted object Else Rhino.DeleteObjects crv02 Rhino.AddTextDot "Failed to loft", arrPtCent(0) End If Next End Sub
Rhinoscript exercise #2:
This second script is a development form the first one. Here, the script demonstrates at how more complex parametric transformations can be developed -3d modular system.
Option Explicit 'Script written by <Dani Hermawan - www.formologix.com > <www.formo.co> 'Script version Friday, 15 July 2011 13:32:45 Call Main() Sub Main() Dim arrCrvs01 : arrCrvs01 = Rhino.GetObjects("Select Curves to offset") Dim arrPtCent Dim crv01 Dim dblDist Dim crvAtt : crvAtt=Rhino.GetObject("Select Curve to evaluate") Dim arrEvaPt Dim dblParam Dim crv02 Dim arrCrvs02 Dim arrCrvs03 Dim dblMove01 : dblMove01=Rhino.GetReal("First Copy distance",0.3) Dim dblMove02 : dblMove02=Rhino.GetReal("Second Copy distance",-0.3) Dim crv03 Dim crv04 Dim startPt Dim startPt01 Dim arrStartPt Dim dblDistCent Dim dblParamPoly Dim strLine Dim strPt For Each crv01 In arrCrvs01 arrPtCent= Rhino.CurveAreaCentroid(crv01) dblParam=Rhino.CurveClosestPoint(crvAtt, arrPtCent(0)) arrEvaPt=Rhino.CurveEvaluate(crvAtt,dblParam,1) dblDist=Rhino.Distance(arrEvaPt(0),arrPtCent(0)) dblDist=dblDist/15 'dblParamPoly=Rhino.CurveClosestPoint(crv01, arrPtCent(0)) arrStartPt = CurveEvaluate(crv01,dblParamPoly,1) strPt = Rhino.AddPoint(arrStartPt(0)) dblDistCent=Rhino.Distance(arrStartPt(0),arrPtCent(0)) If dblDistCent > dblDist Then crv02=Rhino.OffsetCurve(crv01,arrPtCent(0),dblDist) startPt=Rhino.CurveStartPoint(crv02(0)) strLine = Rhino.AddLine(arrPtCent(0),arrEvaPt(0)) Dim z1 : z1=arrPtCent(0)(2)+dblMove01 Dim z2 : z2=arrPtCent(0)(2)+dblMove02 Dim x : x=arrPtCent(0)(0) Dim y : y=arrPtCent(0)(1) Dim arrEnd01 : arrEnd01= Array(x,y,z1) Dim arrEnd02 : arrEnd02= Array(x,y,z2) If Rhino.IsCurveClosed(crv02(0)) Then crv03=Rhino.CopyObject(crv01,arrPtCent(0),arrEnd01) crv04=Rhino.CopyObject(crv01,arrPtCent(0),arrEnd02) arrCrvs02 = Array(crv02(0), crv03) arrCrvs03 = Array(crv02(0), crv04) Rhino.AddLoftSrf arrCrvs02 Rhino.AddLoftSrf arrCrvs03 Else Rhino.DeleteObjects crv02 End If Else End If Rhino.DeleteObject strLine Rhino.DeleteObject strPt Next End Sub
The rhinoscripts above work with Rhino SR7 or above. A key character has to be modified in order to make the script works. It will be mentioned in the workshop.