Best way to create a large text file with a fixed content - panel component?

Hi all,

I have a VB component that creates a text file with geometry data from Grasshopper. It is triggered by a push button, so that it just runs once per “push”.

This output text file is then imported, together with a definition file, into another 3D software for further treatment.

That definition file has a fixed content and is today provided together with my component, but the most frequent user error is that they forget to place the definition file in the same folder as the output file created by the component. (The location & name of the definition file is referenced to in the first lines of the output file, so it all needs to be consistent)

Now, to solve this, I was thinking about storing the content of the definition file in a panel component, and to just have my component spit out the content of that panel as a definition file together with the main file, in the same folder, to reduce user errors.

The problem is that the panel cannot apparently handle the full content of the file (roughly 150 KB), it seems to have a size limit (I saw other topics on the forum related to this).

So… what would be the best way to proceed in your opinion?
The most elegant solution would enable the whole process to be hidden from the user: no need to deliver the definition file with the component if it’s somehow “baked in”, don’t show it in GH, and write it with the right name and in the right place so that it all “just works”.

In earlier days, I implemented a similar solution in Excel VBA: I would then place the content of the definition file on a separate, hidden tab, and through VBA dump the content of that tab, line per line, to the hard drive.

Thanks in advance!

Cyril

Hello,

if you create a custom component, you can always serialise data. Then this data is stored within the gh file.
Now whenever you write your data file, you simple write the definition file from the serialised data.

As an alternative you can also hardcode the file within your vs project, being part of your grasshopper plugin.

Is this what you are after?

Serialisation in Custom Components works by overriding these two methods:
public override bool Write(GH_IO.Serialization.GH_IWriter writer) // Method to write custom data to gh file
public override bool Read(GH_IO.Serialization.GH_IReader reader) // method to read custom data from gh file

Hi Tom,

thanks for getting back to me on this!
I’m not sure that I get all the concepts you mention here: serialize data, storing data within the gh file, etc. Would you have an example somewhere? Where would I place/copy-paste the actual content of the definition file?

Right now I’m just coding directly in a VB script component in GH (so freely editable by any user and doesn’t require VS). But my next step was to indeed move to a proper plugin for GH, to hide the script from the end-user and make it easier to distribute. Would you thus advise to make that step now (moving from VB script component to true plugin through Visual Studioe), in order to make the creation of the definition file easier?

Yes,

I guess the most straightforward step would be using Visual Studio.
I was already assuming that you are using Visual Studio. Both options do only work from there.
You can store anything in your dll/gha file. If you are already familiar with VB scripting, then this next step isn’t that difficult. There is also a Wizard/Template for Grasshopper Plugins for Visual Studio. But be aware. Dot.net Plugins are easy to decompile. If you choose to protect your code from others you might also obfuscate your code. But yes it simplifies distribution, and allows you to do more.

Edit: From a scripting components perspective: You can also store text in the text parameter component or you simply define an unformatted string in your script component.

Then my order of priorities just shifted and I’ll move it to VS first.

The other hints seem also problematic: the text parameter component has apparently the same limit on length as the panel component. And it’s a bit tricky to handle the line breaks when copying the definition files content to the script. Line breaks were handled smoothly in an Excel sheet, I guess I got lucky :slight_smile:

Thanks for your help!

Cyril