Monday, January 1, 2007

FitCurveToLength ( ) _yuki

So far, I just copied tutorial, but my challenge is to scale down the curve within the original. The example on the right is my goal. Now, the scale origin is set to (0,0,0). I have to change the scale origin to the center of gravity. I don't even know if there is a way to specify it.

Option Explicit
'title: FitCurveToLength
'this script is to loop scaling a curve until it fits certain length

FitCurveToLength ()
Sub FitCurveToLength ()
Dim strCurveID
strcurveID = Rhino.GetObject("Select a curve to fit to length", 4, True, True)
If IsNull(strCurveID) Then Exit Sub

Dim dblLength
dblLength = Rhino.CurveLength(strCurveID)

Dim dblLengthLimit
dblLengthLimit = Rhino.GetReal("Length limit", 0.5*dblLength, 0.01*dblLength, dblLength)
If IsNull(dblLengthLimit) Then Exit Sub

If Rhino.CurveLength(strCurveID) <= dblLengthLimit Then Exit Do strCurveID = Rhino.ScaleObject(strCurveID, Array(0,0,0), Array(0.95,0.95,0.95),True)
If IsNull(strCurveID) Then
Rhino.Print "Something went wrong..."
Exit Sub
End If

Rhino.Print "New curve length: " & Rhino.CurveLength(strCurveID)

End Sub