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: 2143

Replies to This Discussion

/*
file content:
0,0,0
12,12,12
1.2,1.22,3.5
12,1.2,1.2
*/

    // read File
    string path = @"C:\Users\you\Desktop\points.txt";
    FileStream my_stream = File.OpenRead(file_path);
    System.IO.StreamReader my_reader = new System.IO.StreamReader(my_stream);
    List<string> my_lines = new List<string>();
    while (my_reader.Peek() >= 0)
    {
      my_lines.Add(my_reader.ReadLine());
    }
    my_stream.Dispose();
    my_reader.Dispose();

    List<Point3d> my_points3d = new List<Point3d>();


    // generate Points
    for(int i = 0;my_lines.Count > i;i++)
    {
      string[] xyz_info = my_lines[i].Split(',');
      Point3d insert_pt = new Point3d(Convert.ToDouble(xyz_info[0]), Convert.ToDouble(xyz_info[1]), Convert.ToDouble(xyz_info[2]));
      my_points3d.Add(insert_pt);
    }

    A = my_points3d;

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