Export geometries into separate files

Hey everyone,
this may be a question for absolute beginners, but I can’t seem to figure it out.

Basically I want to build geometries based on some text file contents within Grasshopper and export these geometries into separate files. Here is a MWE for this issue:
There is a csv-like file with 4 columns: index/row, length, width, height. The last three columns are processed with a C#-script and the values are parsed into x,y and z arrays. Based on these arrays I want to build a simple Box (so n boxes for n rows in the file). Every box should then be exported into a separate step-file. Everything works fine and n files are written properly, but they all contain all the n boxes instead of a single box.

Attached is the gh-file and the text file for n=3 boxes. If you wanna use the gh-file please remember to edit the file paths to your needs.

There also may be a lot of other ways to do these things. Any help would be gladly appreciated!
Thanks in advance.

boxesImportExport.gh (10.1 KB)
parametersToRead.txt (33 Bytes)

This recent thread might be relevant?

P.S. You could simply leave out the “C:\” path in your filename.

This plugin doesn’t work for you?

And you don’t need C# to read and parse a simple file:

Repeat Data makes no sense here, eh?


boxesImportExport_2023Sep7a.gh (13.1 KB)

Thanks for your swift reply @Joseph_Oster and your comments on my file.

I read through the script mentioned in the first part of your answer, but it is not exactly what I am trying to achieve. It is used to put all the geometries into a single file. I want to put the geometries into separate files, 1 file for each geometry configuration in the file.

I also ran your edited script. It works, but even though being much cleaner than my script, the issue with the export persists. After adding the export component (from the Pancake plug-in) it also creates three separate files containing all of the boxes at the same time (so file_1.step, file_2.step and file_3.step with 3 breps in each file). Do you have another idea for the file export?

Thanks again!

Pancake is a bit hard, maybe try Lunchbox, also it depends the type of file you need to export

Yeah, and it wasn’t the simpler version of that concept that I first saw here. Sorry for the misdirection.

Wish I did, this idea could be useful. Maybe graft the boxes and filenames?


boxesImportExport_2023Sep7b.gh (11.1 KB)

1 Like

Yes, this is what’s needed.

I used the Definition Path from Pancake to read source file and write output files to the same directory as the grasshopper file.

boxesImportExport_01.gh (14.3 KB)

-Kevin

2 Likes

Hey @Joseph_Oster and @kev.r,

grafting really did the trick here. Thanks again for your swift help and a solution for this problem.
Have a nice day!

Pancake exports multiple files by branch. I should add more warnings on the ExportAs component if it’s not used properly.

2 Likes

Strictly speaking, I should not have flattened the input to List Length, in case you have multiple geometries in each branch. So I updated my code to use TStat (Tree Statistics) ‘P’ output instead, and added the purple group to generate 10 boxes per branch instead of only one. I also added pcGhFilePath from Kevin’s code so now the parametersToRead.txt file and exported .step files will all be in the same folder as the GH file. That can easily be changed, of course.


boxesImportExport_2023Sep8a.gh (19.1 KB)