Document

References
public class Document : IStorable
The Grasshopper document class. Documents contain all objects, undo record, solution and display logic.

Constructors

Document

#
Deserialization constructor.
public Document(
reader
Reader object.
)

Finalizer

~Document

#
Destructor, this will remove the document from the static global database.
~Document()

Properties

AllDocuments

#
Provides an enumerable list of all Document instances currently still in memory. Documents constructed during the execution of this enumeration will not appear, however documents currently awaiting garbage collection may.
public static IEnumerable<Document> AllDocuments { get; }

Animations

#
Gets the animation server for this document. The server owns the named animations stored in the file, and runs them.
public AnimationServer Animations { get; }

CustomValues

#
Provides an object for storing named custom values that survive file io.
public KeyedValues CustomValues { get; }

Dependencies

#
Gets the dependencies for this document. I.e. which other documents are required for input data.
public DocumentDependencies Dependencies { get; }

Display

#
Gets the display properties for this document.
public DocumentDisplay Display { get; }

File

#
Gets the file accessor for this document.
public FileUtility File { get; }

Globals

#
Gets the globals repository for this document.
public GlobalServer Globals { get; }

Hash

#
Gets the ID associated with this document. This can be a very expensive property to call as it will involve computing a hash of the entire document contents. The hash is cached locally, but wiped whenever the document is modified. Note that the hashing does *not* include undo records, canvas and viewport imagery, or plugin data. However it does include all objects (including all their persistent values), all custom values, and all named views.
public Guid Hash { get; }

Identity

#
Gets the runtime identity of this document. Assigned in the constructor, stable for the lifetime of the in-memory document, and not serialised to disk. Used primarily to name autosave files of unnamed documents so that successive autosaves overwrite the same file. The setter is internal and is intended only for session-restore code that needs to reattach a previously persisted identity to a freshly constructed document.
public Guid Identity { get; }

IsEmpty

#
Gets whether this document is considered empty and not worth saving or keeping. An empty doc must have no objects, no undo records, no file path and no custom values.
public bool IsEmpty { get; }

Methods

#
Gets the actions utility.
public DocumentMethods Methods { get; }

Modifications

#
Gets the number of modification since the last save.
public int Modifications { get; }

Modified

#
Gets whether this document has been modified in any way since the last save. This property just checks to see if the number of Modifications is larger than zero.
public bool Modified { get; }

NamedViews

#
Gets the named view collection of this document.
public NamedViews NamedViews { get; }

Notes

#
Gets or sets the notes on this document. Notes are stored inside the CustomValues object under the StandardKeys.UserNotes key.
public string Notes { get; set; }

Objects

#
Gets the collection of all objects contained within this document.
public ObjectList Objects { get; }

Parent

#
Gets or sets the parent document of this document. Note that this property is not (and indeed cannot) be serialized as part of file IO, so it must be assigned anew, ideally prior to each solution.
public IDocumentParent Parent { get; set; }

Projection

#
Gets the projection details of this document within the canvas. Zoom values less than or equal to zero indicate an unset projection. When documents with unset projections are loaded into a canvas, they will be automatically centred.
public (PointF centre, float zoom) Projection { get; set; }

Solution

#
Provides access to solution related methods for this document.
public SolutionServer Solution { get; }

State

#
Gets or sets the state of the current document.
public DocumentState State { get; set; }

Undo

#
Gets the undo/redo stack for this document.
public History Undo { get; }

ViewportDragging

#
Gets or sets whether shapes in persistent data can be dragged in the viewports while this document is loaded in the canvas. Changing this does not modify the document.
public bool ViewportDragging { get; set; }

Methods

Close

#
Close this document and release all resources and event handlers. After calling this method, no other method should be called.
public void Close()

Modify

#
Increment the modification counter on this document.
public void Modify()

NewActiveDocument

#
Create a new empty, DocumentState.Active document.
public static Document NewActiveDocument()

NewInactiveDocument

#
Create a new empty, DocumentState.Inactive document.
public static Document NewInactiveDocument()

NewInertDocument

#
Create a new empty, DocumentState.Inert document. Inert documents have their Display property set to false.
public static Document NewInertDocument()

Store

#
Write the data inside this document to a writer.
public void Store(
writer,
contents
)

Store

#
public void Store(
writer
)
Store

ToString

#
public override string ToString()
Object.ToString

Unmodify

#
Set the modification count to zero. This happens automatically on save. You should only call this function if there are changes you *don't* want the user to save.
public void Unmodify()

Events

ModifiedChanged

#
This event is raised whenever the modified flag of this document changes.
public event EventHandler<DocumentModifiedEventArgs> ModifiedChanged

ParentChanged

#

StateChanged

#
This event will be raised whenever the document state changes.
public event EventHandler<DocumentStateEventArgs> StateChanged