Accessing clusters as XML

In a GHX file, I see:

<item name="ClusterDocument" type_name="gh_bytearray" type_code="20">
  <stream length="4031">7FgJUBPptg…

Although everything else is text, the clusters are binary. Is it possible to convert that stream to XML and back?

Yes, using GH_IO.dll from a .NET language (eg, C#). Search docs/forum for gh_io for examples and discussion.

Thanks, Tom! It would be great if that works.

I’ve been working on something recently which does this, it works for sure. I’ve been working with binary .gh files using GH_IO api. The value of the stream element in your example is almost certianly base64 encoded. It’s trivial to get a byte array from that (eg, System.Convert.FromBase64String in C#). So something like:

var base64str = ... // TODO: content of <stream> element
var bytes = System.Convert.FromBase64String( base64str );
var archive = new GH_Archive();

If you then want it as XML:

string xml = archive.Serialize_Xml();

To reference GH_IO.dll from a C# project (on Windows, no idea about mac or if it’s even possible), in the .csproj file add as a child of the existing root Project element:

    <PackageReference Include="System.Drawing.Common" Version="8.0.6" />
    <Reference Include="GH_IO" HintPath="$(ProgramFiles)\Rhino 8\Plug-ins\Grasshopper\GH_IO.dll" />

Good luck!

Thank you for sharing the snippet!