GH_Archive from GH_Document

Hi there,
This is a generic question, I am curious to know a way to get the GH_Archive out of a file that is currently in use and it is not saved, I am aware of GH_Archive.ReadFromFile() and GH_Archive.Deserialize_Binary(), but not sure how to serialise the current GH_Document instance or if that is even the correct question.


GH_Archive is a runtime representation of a *.gh or *.ghx file. Are you sure you need to have access to it?

You can use Kernel.GH_DocumentIO to read and write and copy files, it may get you started.

1 Like

Thanks Dave,

Sorry for the late response. Question was due an odd circumstance. I was requested to write a Rhino Plug-In that save and read encrypted grasshopper files without passing through .gh or .ghx. That bullet got dodge for the moment.

But just out of curiosity, is there anyway of getting the binary of a new unsaved file?

for example:

var io = new GH_DocumentIO(GrasshopperDocument);

will put an xml version of the document into the Windows clipboard.

1 Like
internal static bool QuickSaveGh(string filePath, GH_ISerializable ghDoc) {
	try {
		GH_Archive archive = new GH_Archive();
		archive.Path = filePath;
		if (!archive.AppendObject(ghDoc, "Definition")) {
			return false;
		else {
			File.WriteAllBytes(filePath, archive.Serialize_Binary());
		return true;
	catch(Exception e) {
		return false;
1 Like

Many thanks to both @DavidRutten & @gankeyu ,

Both solutions solved my problem. I might replicate Keyu just to avoid using temporarily the clipboard as the user wanted to encrypt the file for security reasons.