CSV Export data lists

Hi there,

I’m trying to export lists using the CSV tool, however can’t work out how to combine them whilst retaining the grouping of data in the second list.
Essentially the excel I am trying to make is the building name and the facade sizes on that building (For the example’s sake, some buildings have 5 facades, some 3 etc)
What I’m currently trying to do:

The format I understand it should be in post CSV tool for proper export into Excel:

CSV Export.gh (8.2 KB)

Thank you for any help!

In order to combine two lists while retaining the grouping of data in the second list, you can use the Join method in C#.

Here is an example:

List<string> list1 = new List<string>() { "A", "B", "C" };
List<string> list2 = new List<string>() { "1", "2", "3" };

var result = list1.Join(list2, x => 1, y => 1, (x, y) => new { x, y });
//This will combine the two lists into a single list of anonymous objects, each containing an element //from list1 and an element from list2.

//You can then use the `result` list to export the data to CSV using CsvHelper library
using (var writer = new StreamWriter("path/to/file.csv"))
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
File.WriteAllLines("path/to/file.csv", result.Select(x => x.x + "," + x.y));

You can make it into a component

Thanks @farouk.serragedine … This isn’t working for me currently though. I’m having errors surrounding the list string to join

You will need placeholders for the blank items as well as have 3 items in your Headers list.

1 Like

Thank you very much @Japhy !

Sorry @Japhy , is there a way to add placeholders to multiple branches at once? I have a list with 41 branches and each have a variety of numbers inside (range from 4 to 14), So would ideally would look for a way of automating this addition of placeholders rather than manually enter them!

(This is the list I am trying to input into the solution you gave above):

Thanks again for any help


Something like this should do the job :

CSV Export.gh (13.7 KB)

1 Like

Note that MagicTeddy doesn’t pass items through the Text Panel, this can be dangerous when working with floats… 1.2020202

1 Like

Thanks both - Found the solution I needed. Much Appreciated!

How do you write the data to a CSV file? So far i’ve only found panel → stream data. Looking for a way to write the file into a directory with a button.

OP used a plug-in called LunchBox.