TEN-Nobuhara_Rings : Series 1


Series 1 by Thad Nobuhara @ smallscalecollective:

Set of parametric rings.  User can design # of faces, size of ring opening, and length of ring.   Project also allows for user to ‘design’ their own profile which is generated along the ring loops.


Option Explicit
‘Ring Script written by <Thad Nobuhara>
‘Script copyrighted by <smallscalecollective>
‘Script version Sunday, December 10, 2008 9:07:55 PM
‘Note: 1.815 is diameter of Thad’s finger

‘Script written for centimeter units

Call Main()
Sub Main()
Dim i, strElpse(), arrPlane
Dim intFacets : intFacets = rhino.GetInteger (“how many sides to your ring?”,16)
If IsNull (intFacets) Then Exit Sub
Dim dblWidth : dblWidth = rhino.GetReal (“how wide would you like your ring? (diameter)”,2.2)
If IsNull (dblWidth) Then Exit Sub
Dim dblLength : dblLength = rhino.GetReal (“how long would you like your ring?”,1)
If IsNull (dblLength) Then Exit Sub
Dim strObj : strObj = Rhino.GetObject(“select profile to orient”,4)
Dim dblRotAngle : dblRotAngle = 360/intFacets
For i = 0 To intFacets – 1
ReDim Preserve strElpse(i)
arrPlane = Rhino.PlaneFromPoints (Array(0,0,dblWidth/2), Array(1,0,dblWidth/2),array(0,1,dblWidth/2))
strElpse(i) = Rhino.AddEllipse (arrPlane,dblWidth/2,dblLength/2)
Call Rhino.RotateObject (strElpse(i),array(0,0,0),i*dblRotAngle,array(0,1,0))
‘call addProfile function
Call orientProfile(strElpse, strObj)
End Sub
Sub orientProfile(strCrvs, strObj)
Dim arrCtPt : arrCtPt = Rhino.CurveAreaCentroid(strObj)

Dim strdecide: strdecide = Rhino.GetString(“wanna try to select points on your own?”,”no”,Array(“yes”,”no”))
Dim objDom : objDom = CurveDomain(strObj)
Dim xP
Dim yP

If strdecide = “no” Then
xP = Rhino.EvaluateCurve(strObj,0)
yP = Rhino.EvaluateCurve(strObj,(objDom(1)-objDom(0))/4)
arrCtPt(0) = Rhino.GetPoint (“center Pt”)
xP = Rhino.GetPoint(,,”pt 1 on X dir”)
yP = Rhino.GetPoint(,,”pt 1 on Y dir”)
End If

Dim vNormal : vNormal = Rhino.VectorAdd (Rhino.VectorUnitize(Rhino.VectorCrossProduct(xP,yP)),arrCtPt(0))
‘Rhino.AddPoint vNormal
‘Rhino.AddTextDot “Nr”, vNormal
‘Rhino.AddPoint arrCtPt(0)
‘Rhino.AddTextDot “arrCtPt(0)”, arrCtPt(0)
‘Rhino.AddPoint (xP)
‘Rhino.AddTextDot “xP”, xP
‘Rhino.AddPoint (yP)
‘Rhino.AddTextDot “yP”, yP

Dim arrPerpPlane : arrPerpPlane = Rhino.PlaneFromFrame(arrCtPt(0),xP,yP)

‘let’s try to do the same with the curves…
Dim strCrv
Dim crvPt, crvTangent, crvPerp, crvNormal
Dim crvCurvature
Dim t

Dim orientObj()
Rhino.EnableRedraw False

For Each strCrv In strCrvs

Dim crvDom : crvDom = Rhino.CurveDomain(strCrv)

Dim arrStPt : arrStPt = Rhino.CurveStartPoint(strCrv)
Dim arrEnPt : arrEnPt = Rhino.CurveEndPoint(strCrv)
Dim m : m=0

For t =0 To crvDom(1) Step (crvDom(1)-crvDom(0))’/2
crvCurvature = Rhino.CurveCurvature(strCrv,t)
If IsNull (crvCurvature) Then
crvPt = Rhino.EvaluateCurve(strCrv,t)
crvTangent = Rhino.VectorUnitize(Rhino.CurveTangent(strCrv,t))
crvPerp = Array(0,0,1)
crvPt = crvCurvature(0)
crvTangent = Rhino.VectorUnitize(crvCurvature(1))
crvPerp = Rhino.VectorUnitize(crvCurvature(4))
End If

crvNormal = Rhino.VectorAdd(Rhino.VectorUnitize(Rhino.VectorCrossProduct(crvTangent,crvPerp)),crvPt)
Dim CrossSectionPlane : CrossSectionPlane = Rhino.PlaneFromFrame(crvPt,crvPerp,crvNormal)
Dim xPtgt : xPtgt = Rhino.VectorAdd(Rhino.VectorUnitize(CrossSectionPlane(1)),crvPt)
Dim zPtgt : zPtgt = Rhino.VectorAdd(Rhino.VectorUnitize(CrossSectionPlane(2)),crvPt)

‘Rhino.AddPoint crvNormal
‘Rhino.AddTextDot “Nr”, crvNormal
‘Rhino.AddPoint xPtgt
‘Rhino.AddTextDot “xPtgt”, xPtgt
‘Rhino.AddPoint zPtgt
‘Rhino.AddTextDot “zPtgt”, zPtgt

Dim strObj2 : strObj2 = Rhino.CopyObject(strObj,Array(0,0,0),Array(0,0,0))

‘We orient the object
ReDim Preserve orientObj(m)
orientObj(m) = Rhino.OrientObject (strObj2,Array(arrCtPt(0),xP,yP),Array(crvPt,xPtgt,crvNormal),1)

‘we scale the object
‘for the scalefactor we need to “unitize” the domain
”   Dim scalefactor, n
”   Dim unitize : unitize = crvDom(1)-crvDom(0)
”   n = 180*(t-crvDom(0))/unitize
”   Rhino.Print(n)
”   If n = 0 Or n Mod 180 =0 Then
”    scalefactor =.5
”   Else
”    scalefactor = .5
”   End If

”   Rhino.ScaleObject orientObj(m),crvPt,Array(scalefactor,scalefactor,scalefactor)
m =m+1
Rhino.Command “-Sweep1 _SelID ” & strCrv & ” _SelID ” & orientObj(0) & “_enter _enter Natural enter enter”
Rhino.DeleteObjects orientObj
Rhino.DeleteObject strCrv
‘” _SelID ” & orientObj(1) & ” _SelID ” & orientObj(2) &

Rhino.EnableRedraw True

End Sub


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s