Aim: to read the contents of a .gh file in a human-readable format like XML, independently from a Rhino instance, e.g. from a C# console application, in order to read the names of the components present in the solution. I can reference whatever assembly needs to be referenced (GH_IO, Grasshopper, rhinocommon…), but I do not want to be runnning a Rhino instance.
Or alternatively, even better, to be able to convert a .gh file as a GH_Document without a running Rhino instance (but I guess this indeed would require a rhino instance).
Is it possible?
I have tried making my own solution to do this, but I always end up getting missing references exceptions at runtime when getting to the conversion step, despite the solution compiling fine.
For example, I manage to read a GH_Archive like this:
public static GH_Archive GHArchive(string filePath)
{
byte[] byteArray = File.ReadAllBytes(filePath);
var byteArchive = new GH_Archive();
if (byteArchive.Deserialize_Binary(byteArray))
return byteArchive;
string Xml = System.Text.Encoding.UTF8.GetString(byteArray).StripBom();
var xmlArchive = new GH_Archive();
if (!xmlArchive.Deserialize_Xml(Xml))
throw new Exception($"Could not deserialize GH_Archive from input ByteArray.");
return xmlArchive;
}
However, in order to understand what components are in the script, I then attempt the conversion of the GH_Archive to GH_Document:
GH_Document ghDocument = new GH_Document();
archive.ExtractObject(ghDocument, "Definition"))
and I get a missing reference exception for rhinocommon_c
– I am not sure what it is, as I can only find a Nuget for RhinoCommon but it does not contain this reference.
Again, just reading the content of the .gh
file (as an XML or anything human-readable) would be enough for me, I don’t need to get a GH_Archive or GH_Document necessarily.
The only constraints are that I need this to be run from a separate executable (e.g. a Console App) and without running Rhino. I thought this might be possible as I’ve tried the “Grasshopper file viewer”, which is an executable that shipped with Rhino that is capable of displaying the contents of a .gh
file as a hierarchical tree.