Tuesday, February 12, 2008

Ready for Another Lattice?
























Here is another practical script for making physical models. I have to explode polylines manually first, then select the segment curves in order to layout for print (with little markers). Since "orient curve" command keeps working in a Loop, I have to Esc out the script, or simply reDim "i" manually for every round.



Option Explicit

layoutPolyline
Sub layoutPolyline

Dim strLine01, strLine02, strLineSave, i, j, arrReference, arrTarget
Dim arrCurve01S, arrCurve01E, arrCurve02S, arrCurve02E
Dim arrTarget1, arrTarget2, strMarker
i = 4
j = i + 0.75

'select an initial line to duplicate and hide
strLine01 = Rhino.GetObject ("select a line", 4)
strLineSave = Rhino.CopyObject (strLine01)
Call Rhino.HideObject(strLineSave)

'orient the line
arrCurve01S = Rhino.CurveStartPoint (strLine01)
arrCurve01E = Rhino.CurveEndPoint (strLine01)

arrReference = Array (arrCurve01S,arrCurve01E)
arrTarget1 = Array (0,-i, 0)
arrTarget2 = Array (99999,-i, 0)
arrTarget = Array (arrTarget1,arrTarget2)

strLine01 = Rhino.OrientObject (strLine01, arrReference, arrTarget)
strMarker = Rhino.AddLine (arrTarget1, Array(0,-j,0))



'select the succeding lines in order
Do
'duplicate and hide
strLine02 = Rhino.GetObject ("select the next line", 4)
strLineSave = Rhino.CopyObject (strLine02)
Call Rhino.HideObject(strLineSave)

'orient lines
arrCurve02S = Rhino.CurveStartPoint (strLine02)
arrCurve02E = Rhino.CurveEndPoint (strLine02)

arrReference = Array (arrCurve02S,arrCurve02E)
arrTarget1 = Array (0,-i, 0)
arrTarget2 = Array (99999,-i, 0)
arrTarget = Array (arrTarget1,arrTarget2)

strLine02 = Rhino.OrientObject (strLine02, arrReference, arrTarget)

arrCurve01S = Rhino.CurveStartPoint (strLine01)
arrCurve01E = Rhino.CurveEndPoint (strLine01)
arrCurve02S = Rhino.CurveStartPoint (strLine02)
arrCurve02E = Rhino.CurveEndPoint (strLine02)

Call Rhino.MoveObject (strLine02, arrCurve02S, arrCurve01E)
Call Rhino.CopyObject (strMarker, arrTarget1, arrCurve01E)

strLine01 = strLine02
Loop

End Sub

Tuesday, February 5, 2008

Something Flowerly













Recent progress in rvb. As it's explained in script,

1. create sphere in spiral, and scale accordingly
2. draw 2d line, rotate, and move
3. rotate sphere in 3D

thats all. Enjoy.





Option Explicit

addVector()
Sub addVector()

Dim arrCoordinate(2), arrPoint(), arrSphere(), arrScaleSphere()
Dim arrLine(), arrSt(2), arrEd(2), arrRotateLine(), dblAngle
Dim arrFinSphere(), arrAxis(), arrLineEd()
Dim i, t, pi, arrScale
Dim A, B, C
i = 0
dblAngle = 30

For t = -5 To 6 Step 0.05

'create sphere in spiral, and scale accordingly ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
A = 1
B = 1
C = t+5
arrScale = Array(A, B, C)

arrCoordinate(0) = t*Sin(5*t)
arrCoordinate(1) = t*Cos(5*t)
arrCoordinate(2) = t

'ReDim Preserve arrPoint(i)
'arrPoint(i) = Rhino.AddPoint(arrCoordinate) 'don't need a string of point to draw a sphere

ReDim Preserve arrSphere(i)
arrSphere(i) = Rhino.AddSphere(arrCoordinate, 0.25)

ReDim Preserve arrScaleSphere(i)
arrScaleSphere(i) = Rhino.ScaleObject(arrSphere(i), arrCoordinate, arrScale)


'draw 2d line, rotate, and move ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
arrSt(0) = arrCoordinate(0)
arrSt(1) = arrCoordinate(1)
arrSt(2) = 0
arrEd(0) = 0
arrEd(1) = 0
arrEd(2) = 0

ReDim Preserve arrLine(i)
arrLine(i) = Rhino.AddLine(arrSt, arrEd)

ReDim Preserve arrRotateLine(i)
arrRotateLine(i) = Rhino.RotateObject(arrLine(i), arrSt, 90)

Call Rhino.MoveObject (arrLine(i), arrSt, arrCoordinate)


'rotate sphere in 3d '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ReDim Preserve arrLineEd(i)
arrLineEd(i) = Rhino.CurveEndPoint (arrLine(i))

ReDim Preserve arrAxis(i)
arrAxis(i)= Rhino.VectorCreate (arrCoordinate, arrLineEd(i))

ReDim Preserve arrFinSphere(i)
arrFinSphere(i) = Rhino.RotateObject (arrScaleSphere(i), arrCoordinate, dblAngle, arrAxis(i))

i = i+1
Next

End Sub