Monday, October 15, 2007

Population Script

This Script takes a bunch of lines and populates another curve to them. Recommended for lasercut.

Option Explicit

Call Populate()
Sub Populate()

Dim Object, ArrLines, i, Popstart, PopEnd, RefPoints, strScale, strOptions, RefObject

strOptions = Array ("y", "n")

Object = Rhino.GetObject ("Select Populate Object", 4)
RefObject = Rhino.GetObject ("Select Reference line for Population", 4)
ArrLines = Rhino.GetObjects ("Select target Curves", 4)
strScale = Rhino.GetString ("Do you want to Scale", "y", strOptions)

Popstart = Rhino.CurveStartPoint(RefObject)
PopEnd = Rhino.CurveEndPoint(RefObject)
RefPoints = Array(Popstart, Popend)

For i = 0 To UBound(arrLines)
Call Copypop(Object, arrlines(i), Refpoints, strScale)
Call Rhino.DeleteObject(arrlines(i))

End Sub

Function CopyPop(Object, Target, Refpoints, strScale)

Dim startPoint, endPoint, TargetPoint, PopCurve, tempCrv, refDist

startPoint = Rhino.CurveStartPoint(target)
endPoint = Rhino.CurveEndPoint(target)
TargetPoint = Array(startPoint, endPoint)
refDist = Rhino.Distance (Refpoints(0), RefPoints(1))

If strScale = "n" Then
Dim targetDist, scalefactor
targetDist = Rhino.Distance(TargetPoint(0), TargetPoint(1))
scalefactor = TargetDist/Refdist
tempCrv = Rhino.ScaleObject(Object, RefPoints(0),Array(scalefactor,1,1) ,vbTrue)
PopCurve = Rhino.OrientObject(TempCrv, RefPoints, TargetPoint)

PopCurve = Rhino.OrientObject(Object, RefPoints, TargetPoint, 3)
End If

End Function