DocumentIO

References
public sealed class DocumentIO
Utility methods for saving and opening documents.

Constructors

DocumentIO

#
Create a new empty IO class. Use this constructor if you wish to Open/Load a file.
public DocumentIO(
document = null,
Document to operate on.
trackFiles = true,
True to add recent-file records.
reportErrors = true,
True to show exceptions in an error window.
retainRoot = false,
True to keep the archive root after opening.
resolvePlugins = true
True to offer the user a way to fetch plugins the file needs but does not have. Turn this off for loads which happen behind the user's back — snippet previews, dependency reads — where a modal window would arrive unbidden.
)

Fields

ClipboardDocumentType

#
public const string ClipboardDocumentType = "GH2DOC"

G1BinaryExtension

#
Gets the extension (including the period) for Grasshopper 1.0 binary files.
public const string G1BinaryExtension = ".gh"

G1DataExtension

#
Gets the extension (including the period) for Grasshopper 1.0 data files.
public const string G1DataExtension = ".ghdata"

G1XmlExtension

#
Gets the extension (including the period) for Grasshopper 1.0 Xml files.
public const string G1XmlExtension = ".ghx"

G2AutoSaveExtension

#
Gets the extension (including the period) for Grasshopper 2.0+ autosave files.
public const string G2AutoSaveExtension = ".ghautosave"

G2BackupExtension

#
Gets the extension (including the period) for Grasshopper 2.0+ backup files.
public const string G2BackupExtension = ".ghbackup"

G2SmlExtension

#
Gets the extension (including the period) for Sml files.
public const string G2SmlExtension = ".sml"

G2ZipExtension

#
Gets the extension (including the period) for Grasshopper 2.0+ files.
public const string G2ZipExtension = ".ghz"

Properties

Compression

#
Gets or sets the compression level used when writing GHZ files.
public Compression Compression { get; set; }

Document

#
Gets the document currently associated with this IO utility.
public Document Document { get; }

DocumentRoot

#
When a document is saved or loaded, and RetainRoot is true, the archive root node is stored here.
public Node DocumentRoot { get; }

ReportErrors

#
Gets or sets whether exceptions are displayed in an Error feedback window.
public bool ReportErrors { get; }

ResolvePlugins

#
Gets whether opening a file offers the user a way to fetch plugins it needs but does not have.

Deliberately separate from ReportErrors. That one governs whether a failure is shown in an error window; this one governs whether the user is asked a question. Session restore wants the second without the first — it reopens the user's own files and should certainly offer to fetch what they need, while a per-file error box at startup would be a menace.

public bool ResolvePlugins { get; }

RetainRoot

#
Retain the root of the archive used to open a document.
public bool RetainRoot { get; }

RootFolder

#
Gets or sets the root folder for Save/Open dialogs to revert to in case the file itself doesn't have a directory yet.
public string RootFolder { get; set; }

TrackFiles

#
Gets or sets whether save and open operations on this instance add recent file records.
public bool TrackFiles { get; }

Window

#
Gets or sets the window which functions as the parent of any Save or Open dialogs. If left unset, the Grasshopper2.UI.Editor.Instance will be used.
public Window Window { get; set; }

Methods

Copy

#
Copy the selected objects of the loaded document into the specified clipboard.
public bool Copy()

Examine

#
Ask the user to pick a file and then examine that file in a custom browser.
public void Examine()

Examine

#
Examine a specific file using a custom browser.
public void Examine(
path,
useConsole
)

Export

#
Export the loaded document to an SML file.
public bool Export(
contents = FileContents.All
)

Export

#
Execute the regular 'Save A Copy' operation on the document hosted in this DocumentIO instance. This is the fundamental save method, all other save methods ultimately call this method, while doing some additional work. This save method will not update the FileUtility.Path of the document getting saved, although it will track the save if the TrackFiles property is true.
public bool Export(
path,
contents = FileContents.All
)

FindScribbleTexts

#
Try and harvest all scribble texts from a document file. This method will read the file, but it will not construct a new Document instance.
public static string[] FindScribbleTexts(
file
)
All scribble texts in this document.

Open

#
Display the open file dialog and load the selected document.
public bool Open(
blockingList = null,
List of already loaded documents used to block a specific file from being opened.
blockingCallback = null
Optional callback in case an already loaded document is picked.
)
True if file was opened, false if opening failed or the loadedList prevented opening.

Open

#
Open the specified file, unless it collides with one of the files in the blocking list.
public bool Open(
path,
blockingList = null,
List of already loaded documents used to block a specific file from being opened.
blockingCallback = null
Optional callback in case an already loaded document is picked.
)
True if file was opened, false if opening failed or the blockingList prevented opening.

Paste

#
Paste the data in the specified clipboard into the document inside this instance.
public bool Paste()

Save

#
Execute the regular 'Save' operation on the loaded document. This will either override the current file if the document is already associated with a URI, or it will open the SAVE FILE dialog.
public bool Save(
contents = FileContents.All
)
True if the file was saved one way or another.

Save

#
Execute the regular 'Save' operation on the loaded document. This will update the document's file association.
public bool Save(
path,
contents = FileContents.All
)

SaveAs

#
Execute the regular 'Save As' operation on the loaded document. This will always show the SAVE FILE dialog, possibly anchored to the current document URI.
public bool SaveAs(
contents = FileContents.All
)
True if the file was saved one way or another.

SaveCopy

#
Execute the regular 'Save A Copy' operation on the loaded document. This will always show the SAVE FILE dialog, possibly anchored to the current document URI, but it will not override the document URI path.
public bool SaveCopy(
contents = FileContents.All
)

SaveCopy

#
Execute the regular 'Save A Copy' operation on the document hosted in this DocumentIO instance. This is the fundamental save method, all other save methods ultimately call this method, while doing some additional work. This save method will not update the FileUtility.Path of the document getting saved, although it will track the save if the TrackFiles property is true.
public bool SaveCopy(
path,
contents = FileContents.All,
method = BackupMethod.Default,
stampFormat = null
)

SaveSnippet

#
Save the document to the central Snippets folder.
public bool SaveSnippet()
True if snippet was saved.

ShowExportDialog

#
Show the Export to Sml dialog and return the selected path.
public string ShowExportDialog(
title,
Dialog title.
pathHint
Optional initial path.
)

ShowOpenDialog

#
public static string ShowOpenDialog(
Window
window,
title,
pathHint
)

ShowSaveDialog

#
Show the Save dialog and return the selected path.
public string ShowSaveDialog(
title,
Dialog title.
pathHint
Optional initial path.
)

TryHarvestCanvasThumbnail

#
Try and get the canvas thumbnail image stored inside a GHZ file.
public static Bitmap TryHarvestCanvasThumbnail(
file
File location.
)
Canvas thumbnail if available.

TryHarvestViewportThumbnail

#
Try and get the viewport thumbnail image stored inside a GHZ file.
public static Bitmap TryHarvestViewportThumbnail(
file
File location.
)
Viewport thumbnail if available.