Hi Mary,
I've removed the crvNum input parameter since it is not needed. The
script below will do what you need (be careful for wrapped lines):
Sub RunScript(ByVal crvList As List(Of OnCurve), ByVal divNum As
Integer)
'This list will contain all our new curves.
Dim crvList2 As New List(Of OnNurbsCurve)
'These will be the normalized arc length point factors.
'Ranging from 0.0 to 1.0
'This array MUST REMAIN INTACT throughout the script.
Dim s(divNum) As Double
For i As Integer = 0 To divNum
s(i) = i / divNum
Next
'Iterate over all curves
For Each crv As OnCurve In crvList
'Create a new array of doubles which will store the division
parameter data.
Dim t As Double() = Nothing
'Divide current curve
If (Not crv.GetNormalizedArcLengthPoints(s, t)) Then Continue
For
'Convert all parameters to actual 3D points.
'Store them directly into an ArrayOn3dPoint, there's no need to
use List(Of On3dPoint) here.
Dim ptList As New ArrayOn3dPoint()
For Each t_param As Double In t
ptList.Append(crv.PointAt(t_param))
Next
'Fit a Curve through the points
Dim fit_curve As OnNurbsCurve = RhUtil.RhinoInterpCurve(3,
ptList, Nothing, Nothing, 0)
'If the fitting failed, we should not add this curve to the
list.
If (fit_curve IsNot Nothing) Then crvList2.Add(fit_curve)
Next
A = crvList2
End Sub
---------------------------------------
There were a number of things that struck me as odd in your original
script:
1. Your loop went from 1 to the Number of curves rather than from 0 to
the number of curves minus one. This meant you were always skipping
the first curve and always overstepping the list of curves which gave
you the error
2. You used the double array called 't' both as input argument and
reference argument in the GetNormalizedArcLengthPoints function. This
function will overwrite the array, which means that after your first
division, the t-array no longer contained normalized arc length
values. I've created a separate array called 's' in my script.
3. Minor thing: you were using a List(Of On3dPoint) to store the
division points, then you would convert this list into an
On3dPointArray. This is an unnecessary step. You might as well use the
On3dPointArray from the get go, it is very similar to List(Of
On3dPoint)
I also posted a screenshot of the new script (in case the source code
in this post gets mangled). I cannot post a file because I'm running a
new version of Grasshopper and the file format might not be forwards
compatible...
--
David Rutten
[email protected]
Robert McNeel & Associates