Grasshopper

algorithmic modeling for Rhino

Hello,

Does anyone know how to create a custom parser inside the Read File component? Specifically I'm trying to separate x,y,z coords from a multi-line CSV file. I tried using this snippet and got nothing:

Public Overrides Function Parse(ByVal data As String, _
Byval options As EH_ReadFileComponent.EH_ParseOptions) As Object

Dim coord As String() = Nothing

coord = data.Split(",")

Dim pos As String

For Each pos In coord

C = coord

Next pos

End Function


I just need to separate X, Y, and Z. should be easy with String.Split(Char()). C is an output so assigning it a value should show the newly parsed info right? Any ideas?

Thanks!

Views: 2141

Replies to This Discussion

Hi Bob,

Please see attached sample. It has two examples, the top imports x,y,z points data and the second imports numbers. Make sure you update the path to show where you are importing the file from.
Attachments:

A follow-on question:

What would be the appropriate code for a tab-delimited file with only x and Y values? I can convert to comma delimited, but I am working with wings and most airfoils are 2-d point files, so that is what I need to read into GH. Thanks very much.

Please disregard I just edited the file and saved it as .csv in Excel. This script is brilliant - just what I needed. Thanks.

'data' and not 'c' is apparently the variable that works as the output.
If your csv file only has 3 numbers per line (the x,y,z coordinates). Just use this line of code:
data = "{" & data & "}"

Even if the output is still a string, when you connect it to a point parameter, it will be converted to a 3d point. In future versions the {} won't be needed.

If your csv file has more data besides the points, and say the points are the 4th, 5th and 6th numbers, use this code:
Dim str_list() As String
str_list = data.split(",")
data = "{" & str_list(3) & "," & str_list(4) & "," & str_list(5) & "}"
You can also use:
Return "{" & data & "}"
I'm no programmer but i guess that's probably more correct.
In fact, you can output a point directly in it's correct data type using this code:

Return New On3dPoint(str_list(0), str_list(1), str_list(2))

As you can tell, I'm figuring out this while i type. Strange that converting the strings to numbers is not necessary to create the point.
nice! no headache.
ok well now i have a headache haha, I got the list parsed and now I'd like to split the array into smaller arrays. How would this be possible, for example if I have an array:

A[] = [1,2,3,4,5,6]

and I want two arrays:

A[] = [1,2,3]
B[] = [4,5,6]


I'm thinking I would need to divide the array A[]/2 in this case to split it. But I'm not sure how to approach this in VB. Any suggestions or hints?
What are you trying to output per line? I don't think you can output multiple arrays. To create a list of values per line, you'll have to use paths. For this it would be better to connect the file parser component to a scripting component. There's an example in the forum for creating paths inside a scripting component.
Per line is just x,y,z. Multiple paths are exactly what I need. For example, if the point file has 100 points i'd like to create 10 paths each containing 10 points. I'll search the forum. Thanks for the tip.
hmm.... if each line consists of only one point, why did you want to split an array in two in the first place? I thought maybe each line consisted of multiple points. You don't actually need a scripting component for this. If you have a 1 dimensional list of 100 points and you want them in 10 lists of 10 points each, you can recreate the desired tree structure using two series components and a list item component.
Vincent,

The points are specific, coming from a txt file, So recreating the points using Series components won't give me the positions I want. I posted a video earlier showing those points coming from Processing. The code in Processing uses attractors and every loop(), N points(particles) are redrawn showing the result of the attractors. So given that i know how many particles are in the first generation, say 10, i could split the list into multiples 10 and use a Control Point Curve to connect the points illustrating the vector of each point. That's why it would be nice to have paths for each particle and it's consecutive generations. Hopefully that makes sense.

Btw, is there a reply-limit on Ning? seems i can't reply to your post but only to my original post.

cheers!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service