Get Grasshopper Document Object Count without opening grasshopper



I’m wanting to do a sort of ‘health check’ on our company grasshopper files.
I’d like to get some information from each file such as:

  • object count
  • author
  • plugins
  • used components
  • preview mode (hidden, wireframe, shaded)
  • preview mesh setting (disable, low, high, document etc)

I was hoping to do this in a c# console app using GH_IO.dll
So far all i can do is read a .gh file from a filepath and write it to .ghx
This seems a pretty useful start, but not enough.
(thanks @DavidRutten for posting a while back)

I loathe the idea of doing xml scraping Python: Parse ghx files with ElementTree? i think @chanley settled on
@andheum’s excellent solution from within grasshopper.

except for this problem

has anything changed since 2017? Any suggestions to take this further?

This is my test app so far

Program.cs (1.1 KB)

(David Rutten) #2

Use GH_IO directly to inspect the files. Get the root object and start looping over subchunks and items. You can use the Grasshopper FileViewer.exe to look at the names of chunks in the file hierarchy, so you’ll know what to look for at each level.

At home now with only an iPad, but I can code up a small example later today.


Thanks David,
I haven’t come across the grasshopper file viewer before. Will check it out when I’m back in the office.
So you can get the chunks from GH_Archive.GetRootNode()? I thought I tried that (commented out in screen shot) but mistook it for a dead end. Yes please an example would be nice!

(David Rutten) #4

Program.cs (6.8 KB) (44.0 KB)

This is a typical function which extracts and displays some information stored in a GH_Archive instance. The code could probably have more error checking if you want it to deal with corrupt files too, although it is extremely unlikely that a *.gh file is corrupt and still in any way, shape or form readable. The file is compressed so any damage to it at all will cause a failure in decompression.

    private static void DisplayDocumentStatistics(GH_Archive archive)
      var root = archive.GetRootNode;
      var definition = root.FindChunk("Definition");
      var header = definition.FindChunk("DocumentHeader");
      var properties = definition.FindChunk("DefinitionProperties");

      var archiveVersion = root.GetVersion("ArchiveVersion");
      var pluginVersion = definition.GetVersion("plugin_version");
      var documentId = header.GetGuid("DocumentID");
      var documentDate = properties.GetDate("Date");
      var documentName = properties.GetString("Name");

      Console.Write("Archive Version: "); WriteLine(ConsoleColor.DarkCyan, archiveVersion.ToString());
      Console.Write("Plug-In Version: "); WriteLine(ConsoleColor.DarkCyan, pluginVersion.ToString());
      Console.Write("Document ID:     "); WriteLine(ConsoleColor.DarkCyan, $"{{{documentId}}}");
      Console.Write("Document Date:   "); WriteLine(ConsoleColor.DarkCyan, documentDate.ToLongDateString() + " " + documentDate.ToLongTimeString());
      Console.Write("Document Name:   "); WriteLine(ConsoleColor.DarkCyan, $"'{documentName}'");

Grasshopper file properties display
Can GH definitions (.gh) be made searchable?

Excellent thank you!