GH_Archive

References
public class GH_Archive
This is the base archive class which takes care of all (de)serialization and messaging.

Properties

FileName

#
Gets the filename (without extension) of the currently loaded data tree. If the path field has not been set, "unnamed" is returned.
public string FileName { get; }

GetRootNode

#
Gets the root node of this archive. Typically you do not need to modify the Root. Use functions like CreateTopLevelNode(), AppendObject() and ExtractObject() instead. If you modify the Root node, you may corrupt the archive.
public GH_Chunk GetRootNode { get; }

GH_IO_Version

#
Gets the version number of the current GH_IO build.
public static GH_Version GH_IO_Version { get; }

GrasshopperBinaryExtension

#
Gets the file extension (including the dot) associated with Grasshopper® Binary data.
public static string GrasshopperBinaryExtension { get; }

GrasshopperUserExtension

#
Gets the file extension (including the dot) associated with Grasshopper® User Object file.
public static string GrasshopperUserExtension { get; }

GrasshopperXmlExtension

#
Gets the file extension (including the dot) associated with Grasshopper® XML data.
public static string GrasshopperXmlExtension { get; }

IsBinaryPath

#
Gets a value that indicates whether the Path field points to a Binary Grasshopper file.
public bool IsBinaryPath { get; }

IsPath

#
Gets a value that indicates whether or not the path field has been set.
public bool IsPath { get; }

IsXmlPath

#
Gets a value that indicates whether the Path field points to an Xml Grasshopper file.
public bool IsXmlPath { get; }

Messages

#
Gets the internal list of messages.
public List<GH_Message> Messages { get; }

Path

#
Gets the path to the file from which this archive was read and/or written to. If the archive hasn't been read or written yet, this field will be null.
public string Path { get; set; }

WorstCaseMessageType

#
Gets the worst case message type. If the record contains at least 1 error, the worst case is GH_Message_Type.error. If the record contains no errors, but at least 1 warning, the worst case is GH_Message_Type.warning. If the record contains no messages or only infos, the worst case type is GH_Message_Type.info.
public GH_Message_Type WorstCaseMessageType { get; }

Methods

AddMessage

#
Add a new message to the record.
public void AddMessage(
message
Message to add
)
ArgumentNullExceptionThrown if the message is a null reference.

AddMessage

#
Add a new message to the record.
public void AddMessage(
messageText,
Message text.
messageType
Message type.
)
ArgumentNullExceptionThrown if message text is null or empty.

AppendObject

#
Appends a target object into the root node of this archive tree. If the root doesn't exist yet, it will be created. Existing objects at the root scope will not be affected.
public bool AppendObject(
target,
Object to append. Cannot be null.
targetName
Name of object to append, name must be unique.
)
True on succes, false on failure.
ArgumentNullExceptionThrown if target is a null reference.
ArgumentNullExceptionThrown if the target_name is null or empty.
This sample shows how to create a new archive and serialize a single top level object.
bool CreateFile(string file_name, GH_ISerializable target, string target_name) 
{
  GH_Archive archive = new GH_Archive();
  archive.AppendObject(target, target_name);
  return archive.WriteToFile(file_name, true);
}

ClearMessages

#
Remove all messages from the log.
public void ClearMessages()

CreateNewRoot

#
Discards the current data tree and instantiates a new root node. This root node contains some comments, a version value containing the current version of GH_IO.dll and a DateTime value containing the current date and time.
public void CreateNewRoot(
forWriting
If true, all data fields are reset.
)

CreateTopLevelNode

#
Creates and returns a new root node for this archive in the form of a GH_IWriter instance. Typically you do not call this method. If you want to add an object to the archive, use AppendObject() instead.
public GH_IWriter CreateTopLevelNode(
rootName
Name of root object.
)
The GH_IWriter incarnation of the GH_Chunk that represents the new Node.

Deserialize_Binary

#
Deserializes an array of bytes.
public bool Deserialize_Binary(
byte[]
data
Byte array to deserialize.
)
True on success, false on failure.
ArgumentNullExceptionThrown if data is a null reference.

Deserialize_Xml

#
Deserializes an Xml string.
public bool Deserialize_Xml(
xmlContent
Xml to deserialize.
)
True on success, false on failure.
XmlExceptionThrown if xml_content is not a valid Grasshopper Xml stream.

ExtractObject

#
Extract a target object from the data tree.
public bool ExtractObject(
target,
Object to extract. Cannot be null.
targetName
Name of object to extract, name must identify an existing chunk.
)
True on succes, false on failure.
MemberAccessExceptionThrown if the Root node hasn't been instantiated yet.
ArgumentNullExceptionThrown if target is a null reference.
ArgumentNullExceptionThrown if the target_name is null or empty.
MemberAccessExceptionThrown if the target_name cannot be resolved.

MessageCount

#
Gets the number of messages recorded since the most recent IO operation began.
public int MessageCount()
The number of recorded messages.

MessageCount

#
Gets the number of messages recorded since the most recent IO operation began. Message count can be filtered by message type.
public int MessageCount(
includeInfo,
If true, info messages will be included in the count.
includeWarnings,
If true, warnings will be included in the count.
includeErrors
If true, errors will be included in the count.
)
The number of recoded messages that pass the type filters.

OpenFileDialog

#
Displays a standard OpenFileDialog with all the fields set to cater for Grasshopper files.
public static bool OpenFileDialog(
title,
Title of the dialog. If null, the default title will be used.
ref string
filePath,
Path to file picked by user. If file_path represents a valid string, the dialog is set up to match.
additionalFilters
A list of additional file format filters or null. Filter strings must be in typical FileDialog.Filter syntax: "File Name (*.ext)|*.ext"
)
True is user picked a path, False if user cancelled.

ReadFromFile

#
Reads a new archive tree from a file.
public bool ReadFromFile(
fileName
Path of file to parse.
)
True on success, false on failure. If the read operation fails, all the member fields of this archive ought to be treated as invalid.
FileNotFoundExceptionThrown if the file doesn't exist.
IOExceptionThrown if the file_name doesn't represent a known file extension.

SaveFileDialog

#
Displays a standard SaveFileDialog with all the fields set to cater for Grasshopper files.
public static bool SaveFileDialog(
title,
Title of the dialog. If null, the default title will be used.
ref string
filePath,
Path to file picked by user. If file_path represents a valid string, the dialog is set up to match.
additionalFilters
A list of additional file format filters or null. Filter strings must be in typical FileDialog.Filter syntax: "File Name (*.ext)|*.ext"
)
True is user picked a new path, False if user cancelled.

Serialize_Binary

#
Serializes the data tree into a Binary byte array.
public byte[] Serialize_Binary()
A byte array containing the Binary stream.
MemberAccessExceptionThrown if the root of the current archive hasn't been instantiated yet.

Serialize_Xml

#
Serializes the data tree into an Xml string.
public string Serialize_Xml()
A string containing the Xml content.
MemberAccessExceptionThrown if the root of the current archive hasn't been instantiated yet.

ShowMessageLog

#
Displays the message log viewer. You should typically only display the viewer if the WorstCaseMessageType equals GH_Message_Type.warning or GH_Message_Type.error
public DialogResult ShowMessageLog()
The closing flag for the displayed log form.

WriteToFile

#
Writes the current tree to a file.
public bool WriteToFile(
fileName,
Path of file to write to. If the extension is not a recognized Grasshopper extension, an exception will be thrown.
overwrite,
True to overwrite file at specified location.
rememberPath
If True, the MRU path field will be updated to reflect the new path.
)
True on succes, false if file already exists and overwrite is set to false.
MemberAccessExceptionThrown if the root of the current archive hasn't been instantiated yet.
ArgumentNullExceptionThrown if file_name is either null or empty.
IOExceptionThrown if the file_name doesn't represent a known file extension.