Create .ghx files from Python environment (without grasshopper)

Hello community,

I’m facing the following problem: I need to generate .ghx files from a python environment (outside of grasshopper). Grasshopper is not installed on the machine that should create the .ghx files.

I understand that the .ghx file is basically in XML format. While theoretically humanly readable, I have some problems digging into the file structure.

Even a simple .ghx file with one grasshopper component (e.g. a point) contains hundreds of lines.

My question: Is there documentation about the .gh file structure anywhere? I’ve been searching for days but couldn’t find anything.

Also, if anybody has attempted something similar, I’d be happy for any related python code that I can study.

Thanks a lot.

There is a library called GH_IO.dll that has the purpose of creating .GHX files. @DavidRutten can probably tell more details.

as far as I understand the GH_IO.dll converts .gh files to .ghx files, which is not really what I want to do. I don’t have .gh files available, I need to write the .ghx files from scratch.

Unless you’re talking about decompiling the GH_IO.dll file to maybe get some hints about the .ghx file structure? I think, digging into the .ghx tree by hand will probably give me a better understanding.

It can do that, but it does much more. the gh and ghx formats are binary and xml flavoured serialisations of a strongly-typed-and-indexed-hierarchical-dictionary which is used in-memory to (de)serialise all manner of data.

Although there are common patterns, it is up to each individual component to decide how it wishes to store its data, so you cannot simply predict what the exact contents of a gh file will be given some component.

GH_IO can be used to read gh and ghx files and load them into the dictionary type in memory. It can be used to modify the dictionary (add or remove values and chunks) and ultimately save it to a gh or ghx file again. But the file format is utterly unaware of Grasshopper and Rhino itself. It has no idea what sort of data it is storing, or what it might mean, or what signifies invalid or corrupt data.

GH_IO can be used to read gh and ghx files and load them into the dictionary type in memory. It can be used to modify the dictionary (add or remove values and chunks) and ultimately save it to a gh or ghx file again

Can I see the structure of this dictionary somewhere?
Would it be possible to create this dictionary in Python and then convert it to .gh or .ghx with the help of the GH_IO.dll?

If you drag a gh file onto the canvas, then hover over the pagecurl and move the mouse over the ‘examine’ option you can browse the dictionary.

This is just a shortcut way to invoke the GH_IO_Viewer.exe program which comes installed with grasshopper.