Grasshopper

algorithmic modeling for Rhino

Hello, I am trying to parse a tab delimited file into 3 numbers for each line, then average the 3, and then output a list of those averages. The input data file looks like this:

9.985128e+001 8.776654e+001 6.538765e+001
4.326789e+001 9.534523e+001 4.223425e+001
5.675645e+001 4.445322e+001 2.335634e+001

I have been trying to modify the script example in the grasshopper primer which handles comman separated list. But I keep getting errors output about one dimensional array or Double not having contructors. I have replaced the On3Point with Double and the "," with " "
The non-working script is :
Sub RunScript(ByVal path As String)
If (Not IO.File.Exists(path)) Then
Print("Exit without reading")
End If
Dim lines As String() = IO.File.ReadAllLines(path)
If (lines Is Nothing) Then
Print("File has no content")
Return
End If

Dim avgs As New List(OfDouble)

For Each line As String In lines
Dim parts As String() = line.Split(" ".ToCharArray())
If UBound(parts) <> 2 Then Continue For
Dim r As Double = Convert.ToDouble(parts(0))
Dim g As Double = Convert.ToDouble(parts(1))
Dim b As Double = Convert.ToDouble(parts(2))

avgs.Add(New Double((r + g + b) / 3))
Next
A = avgs
End Sub

Any thoughts or code you coule point me to?
Thanks, Jeff

Views: 865

Replies to This Discussion

avgs.Add(New Double((r + g + b) / 3))
maybe should become
avgs.Add(((r + g + b) / 3))

there's no constructor for the Double type which means you can't do q = new Double(42.42) you just have to say dim q as double : q = 42.42.
that last statement wasn't working.
Thanks, it works fine.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service