Document

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

Constructors

Document

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

Finalizer

~Document

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

Properties

AllDocuments

#
public static IEnumerable<Document> AllDocuments { get; }
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.

Animations

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

CustomValues

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

Dependencies

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

Display

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

File

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

Globals

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

Hash

#
public Guid Hash { get; }
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.

Identity

#
public Guid Identity { get; }
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.

IsEmpty

#
public bool IsEmpty { get; }
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.

Methods

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

Modifications

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

Modified

#
public bool Modified { get; }
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.

NamedViews

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

Notes

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

Objects

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

Parent

#
public IDocumentParent Parent { get; set; }
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.

Projection

#
public (PointF centre, float zoom) Projection { get; set; }
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.

Solution

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

State

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

Undo

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

ViewportDragging

#
public bool ViewportDragging { get; set; }
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.

Methods

Close

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

Modify

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

NewActiveDocument

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

NewInactiveDocument

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

NewInertDocument

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

Store

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

Store

#
public void Store(IWriter writer)
writer (IWriter)
Store

ToString

#
public override string ToString()
Object.ToString

Unmodify

#
public void 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.

Events

ModifiedChanged

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

ParentChanged

#

StateChanged

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