GH_DocumentIO

public sealed class GH_DocumentIO
Provides basic IO operations for GH_Documents.

Constructors

GH_DocumentIO

#
public GH_DocumentIO()
Create a new instance of GH_DocumentIO without an internal document.

GH_DocumentIO

#
public GH_DocumentIO(GH_Document internal_doc)
Create a new instance of GH_DocumentIO with an internal document.
internal_doc (GH_Document)Document to internalise.

Properties

DisableOverwriteProtection

#
public static bool DisableOverwriteProtection { get; set; }
Gets or sets whether the file overwrite protection dialog ought to be shown during risky saves.

Document

#
public GH_Document Document { get; set; }
Gets or sets the internal document.

IsDocument

#
public bool IsDocument { get; }
Gets a value indicating whether or not this instance of GH_DocumentIO contains an internal document.

LocalClipboardContent

#
public string LocalClipboardContent { get; set; }
Gets the contents of the local clipboard.

Methods

ClearClipboard

#
public void ClearClipboard(GH_ClipboardType clipboard)
Clear the Clipboard Text content. This function wipes both the Text and UnicodeText clipboard fields.
clipboard (GH_ClipboardType)

Copy

#
public bool Copy(GH_ClipboardType clipboard, bool limitToSelection)
Copy the internal document into the clipboard.
clipboard (GH_ClipboardType)Specifies the clipboard type to use.
limitToSelection (bool)If true, only the selected objects will be copied.
True on success, false on failure.

Copy

#
public bool Copy(GH_ClipboardType clipboard, IEnumerable<Guid> guids)
Copy the specified objects in the internal document into the clipboard.
clipboard (GH_ClipboardType)Specifies the clipboard type to use.
guids (IEnumerable<Guid>)List of object ids to copy.
True on success, false on failure.

Copy

#
public bool Copy(GH_ClipboardType clipboard)
Copy the internal document into the clipboard.
clipboard (GH_ClipboardType)Specifies the clipboard type to use.

GetDocumentIcon

#
public static Bitmap GetDocumentIcon(string filePath, Size size)
Try and extract the icon image of a document. Not all gh/ghx files contain an icon so this function may return null. The document itself is not loaded and rendered, so the icon really has to be part of the file already.
filePath (string)Filepath to examine.
size (Size)
An icon bitmap on success or null on failure. Caller is responsible for disposing of the image.

GetDocumentThumbnail

#
public static Bitmap GetDocumentThumbnail(string filePath)
Try and extract the preview image of a document. Not all gh/ghx files contain a thumbnail so this function may return null. The document itself is not loaded and rendered, so the thumbnail really has to be part of the file already.
filePath (string)Filepath to examine.
A preview bitmap on success or null on failure. Caller is responsible for disposing of the image.

Open

#
public bool Open()
Perform a default Open operation and store the result as the internal document.
True on success, false on failure.

Open

#
public bool Open(string filePath)
Open the file at the given location.
filePath (string)Path of Grasshopper file to open.
True on success, false on failure.

OpenDocumentDialog

#
public string OpenDocumentDialog(string path = null, string title = "Open…")
Display the Open GH/GHX dialog.
path (string = null)Optional default path.
title (string = "Open…")Title of dialog.
FileName specified via the Open dialog or null if the dialog was cancelled.

Paste

#
public bool Paste(GH_ClipboardType clipboard)
Deserialize a Grasshopper document from the clipboard. On success, the internal document of this GH_DocumentIO instance will be set.
clipboard (GH_ClipboardType)Specifies the clipboard type to use.
True on success, false on failure.

Save

#
public bool Save()
Perform a default Save operation on the internal document.
True on success, false on failure.

SaveAs

#
public bool SaveAs()
Perform a default Save As operation on the internal document.
True on success, false on failure.

SaveAsCopyDocumentDialog

#
public string SaveAsCopyDocumentDialog(string path = null)
Display the Save As Copy GH/GHX dialog.
path (string = null)Optional default path.
FileName specified via the Save As Copy dialog or null if the dialog was cancelled.

SaveAsDocumentDialog

#
public string SaveAsDocumentDialog(string path = null)
Display the Save As GH/GHX dialog.
path (string = null)Optional default path.
FileName specified via the Save As dialog or null if the dialog was cancelled.

SaveBackup

#
public bool SaveBackup()
Save a time-stamped copy of the current file.
True on success, false on failure.

SaveDocumentDialog

#
public string SaveDocumentDialog(string path = null, string title = "Save…")
Display the Save GH/GHX dialog.
path (string = null)Optional default path.
title (string = "Save…")Title of dialog.
FileName specified via the Save dialog or null if the dialog was cancelled.

SaveQuiet

#
public bool SaveQuiet(string path)
Quietly save a file to a given location.
path (string)
True on success, false on failure.

ShowOverwriteDialog

#
public static int ShowOverwriteDialog(string filename, DateTime lastSave, DateTime fileOnDisk)
filename (string)
lastSave (DateTime)
fileOnDisk (DateTime)

ShowOverwriteDialog

#
public static int ShowOverwriteDialog(string filename)
filename (string)

SubsidiaryDocumentSavePrompt

#
public static DialogResult SubsidiaryDocumentSavePrompt(GH_Document document)
Display a 'stuff has changed do you want to save' message box with Yes/No/Cancel options.
document (GH_Document)Top level document.
Yes, No, Cancel or None state.

SubsidiaryDocumentSavePrompt

#
public static DialogResult SubsidiaryDocumentSavePrompt(string documentName, bool modified, int modifiedSubsidiaries)
Display a 'stuff has changed do you want to save' message box with Yes/No/Cancel options.
documentName (string)Name of top level document.
modified (bool)Boolean indicating whether top-level document is modified.
modifiedSubsidiaries (int)Number of modified subsidiary documents.
Yes, No, Cancel or None state.