C# csv to List script

Hello everybody
Tell me, can anyone have a node code for a grasshopper to read a csv file and then write data from this file, for example, to List<>?

A csv file has multiple rows of data, with each row having multiple values. So a List<T> can’t really store that complexity, unless each row encodes a single data item such as a point or a colour.

Can you be more explicit about what the data in your csv file represents.

1 Like

Thank you very much for your answer, while I’m just interested in importing the data of a simple table by row-divided into rows.

the goal of all is to create a node that will take data from the table, read data from the csv file and output it to the grasshopper

for example, we read this csv file, and set the node to the value B20 and it displays the data associated with this index, in this case B20 is d 4

I hope I explained clearly :innocent:
maybe someone already did something like that? :grinning:

or can this problem be solved in a simpler way?


read in gh.csv (99 Bytes)

If you don’t really need to develop a component…

(1) If your data needs to be organized the way as in your picture, use LunchBox’s Read CSV.

And Create CSV to create such a file.

lunchbox_csv.gh (6.5 KB)

(2) If your data is organized transposed and with a header (which is probably more natural), such as:


You may use Pancake for its CSV read/write support.

pancake_csv.gh (9.6 KB)

1 Like

csv extractor.gh (17.1 KB)


Guys thank you very much :grinning: :+1:
and it is possible to make all this as in c sharp in the form of one node?
can there be any example of how to correctly read the csv file and then output data on the parameter?

using System;
using System.Collections;
using System.Collections.Generic;

using Rhino;
using Rhino.Geometry;

using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;

using System.IO;

/// <summary>
/// This class will be instantiated on demand by the Script component.
/// </summary>
public class Script_Instance : GH_ScriptInstance
#region Utility functions
  /// <summary>Print a String to the [Out] Parameter of the Script component.</summary>
  /// <param name="text">String to print.</param>
  private void Print(string text) { /* Implementation hidden. */ }
  /// <summary>Print a formatted String to the [Out] Parameter of the Script component.</summary>
  /// <param name="format">String format.</param>
  /// <param name="args">Formatting parameters.</param>
  private void Print(string format, params object[] args) { /* Implementation hidden. */ }
  /// <summary>Print useful information about an object instance to the [Out] Parameter of the Script component. </summary>
  /// <param name="obj">Object instance to parse.</param>
  private void Reflect(object obj) { /* Implementation hidden. */ }
  /// <summary>Print the signatures of all the overloads of a specific method to the [Out] Parameter of the Script component. </summary>
  /// <param name="obj">Object instance to parse.</param>
  private void Reflect(object obj, string method_name) { /* Implementation hidden. */ }

#region Members
  /// <summary>Gets the current Rhino document.</summary>
  private readonly RhinoDoc RhinoDocument;
  /// <summary>Gets the Grasshopper document that owns this script.</summary>
  private readonly GH_Document GrasshopperDocument;
  /// <summary>Gets the Grasshopper script component that owns this script.</summary>
  private readonly IGH_Component Component;
  /// <summary>
  /// Gets the current iteration count. The first call to RunScript() is associated with Iteration==0.
  /// Any subsequent call within the same solution will increment the Iteration count.
  /// </summary>
  private readonly int Iteration;

  /// <summary>
  /// This procedure contains the user code. Input parameters are provided as regular arguments,
  /// Output parameters as ref arguments. You don't have to assign output parameters,
  /// they will have a default value.
  /// </summary>
  private void RunScript(string file, string key, ref object data)
    var csv = File.ReadAllLines(file);
    if(csv.Length == 0)
    var keyList = csv[0].Split(',');
    var index = -1;
    for(var i = 0;i < keyList.Length;i++)
      if(keyList[i].Trim() == key)
        index = i;

    if(index == -1)

    var list = new List<string>(csv.Length - 1);
    for(var i = 1;i < csv.Length;i++)
      var dataRow = csv[i].Split(',');
      if(dataRow.Length <= index){
    data = list;

  // <Custom additional code> 

  // </Custom additional code> 
1 Like

Thank you so much!!!

I’ll analyze your code now, I need to understand how it works !!

Rays of gratitude !!! Thank you very much!