Grasshopper

algorithmic modeling for Rhino

I've used a bit of RhinoScript before but this is my first foray into VB.NET.

 

I have a single end point and a collection of start points. I want to create vectors from each start point to the same end point and store them together in an array.

 

Below is my attemp but keep getting the error: Index was out of range. Must be non'negative and less than the size of the collection. Parameter name: index (line:0)

From what I can gather it is either the way I've defined the vector array (vecSunRays) or the way the loop is using 'i'?

 

Private Sub RunScript(ByVal Mesh As Mesh, ByVal OMesh As Mesh, ByVal PtEnd As Point3d, ByVal PtStart As List(Of Object), ByRef A As Object)

Dim dblTol As Double = doc.ModelAbsoluteTolerance
Dim vecSunRays As New List (Of Vector3d)
Dim vecTemp As New Vector3d
'Dim x,y,z As New Double
Dim i As Integer = 0

For i = 0 To PtStart.Count - 1

vecTemp.X = PtEnd.X - PtStart(i).X
vecTemp.Y = PtEnd.Y - PtStart(i).Y
vecTemp.Z = PtEnd.Z - PtStart(i).Z

vecSunRays.Add(vecTemp)

Next

 

Thanks in advance.

Views: 1682

Replies to This Discussion

ByVal PtStart As List(Of Object)

 

this looks a bit icky, shouldn't that be List(Of Point3d)?

 

This is how I'd write that loop:

 

Dim rays As New List (Of Vector3d)
For i As Integer = 0 To PtStart.Count - 1

  rays.Add(ptEnd - ptStart(i))
Next

 

I don't see anything immediately wrong with your code, though I find it peculiar that the error message claims it happened on line:0. Typically you only get line:0 errors when there is a fundamental problem during compilation, but an index-out-of-range error is usually a runtime bug, not a compile-time bug.

 

I think you'll need to post the entire script (or only that part of it which is causing problems) so we can run it on out own machines.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

There is no difference between Integer and Int32, they are different names for the same thing. Int32 is the official .NET framework name for the type and works both in VB and C#. Integer is available to VB programmers as a form of legacy support, as is int for C# programmers.

 

If you have a script that works when using Integer but doesn't when using Int32 I'd very much like to see it.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service