Grasshopper

algorithmic modeling for Rhino

Hello everybody.

I am writing a piece of VBScript and I continuously receive a runtime error that says "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index (line :0)"

I'm trying to evaluate list items against each other in the script. Here's the code.

Private Sub RunScript(ByVal listA As List(Of Double), ByVal listB As List(Of
Double), ByVal minDist As System.Object, ByVal bracketDistMin As
System.Object, ByVal bracketDistMax As System.Object, ByRef distFix As
Object)

    Dim masterList As New List(Of Double)
    Dim i As Integer

    For i = 0 To (listA.Count - 1)
      ' If Value is less than desired input, value is rounded up to minDist
      If (listA.Item(i) - listB.Item(i)) <= minDist Then
        masterList.Add(minDist)

        ' If list value is between a threshold above bracketDistMin and below bracketDistMax
        ' the value is rounded up or rounded down based on the mean between the two variables
      Else If (listA.Item(i) - listB.Item(i)) < bracketDistMax > bracketDistMin Then
        If (listA.item(i) - listB.Item(i)) < ((listA.Item(i) + listB.Item(i)) / 2) Then
          masterlist.Add(bracketDistMin)
        Else
          masterlist.Add(bracketDistMax)
        End If

        ' In all other cases, keep difference the same
      Else
        masterlist.Add(listA.Item(i) - listB.Item(i))

      End If
    Next

    distFix = masterList
   
  End Sub

If there was a way to preform all these operations without VB, I would
love to know. I studied Java for about a year around 6 years ago, and I
don't have any experience in VB other than what I have been working on
today, so I would like some help!

Views: 1524

Replies to This Discussion

Components that compare numbers are available in grasshopper. These components return true or false. These true/false outputs can be used to divide the list by using the dispatch component. After the list has been dispatched, one part of the original list can be altered, the other part stays untouched. Using the same true/false pattern the two list can be weaved back together again.

I think it's not that diffucult to do it all in Grasshopper without using code.
Hi,

that exception is probably due to the fact that listA and listB do not have the same length.
So, I just added the check on both lists, using the length of the shorter one.

Since you used Java earlier, you might find C# interesting. I quickly changed the sample to that language, translating the first part with the .net code converter.

I hope this is useful.

- Giulio
____________
giulio@mcneel.com
McNeel Europe, Barcelona
Attachments:
Hi,

Are you sure both ListA and ListB are at the same size (or at least ListB longer than ListA)?
you never test to see if ListB.item(i) even exists.
Shift lists > Did you change the wrap boolean to true?

The last item becomes the first item.
Don't know if this is usefull.
Grasshopper components only.
Not sure if it's exactly like your script, but you get the idea.
Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service