The Autodesk.Revit.DB.Document class is a fundamental part of the Revit API. It represents the Revit model document, which contains all the data and information for a specific project or file.
public class Document : Element
The Document class has several constructors, but the most commonly used one is:
public Document()
This constructor creates a new Revit document.
ActiveView: Gets or sets the active view for the document.
Application: Gets the Autodesk.Revit.ApplicationServices.Application object associated with the document.
FamilyManager: Gets the Autodesk.Revit.DB.FamilyManager object associated with the document.
Families: Gets the FamilySymbol objects that are defined in the document.
IsModified: Gets a value indicating whether the document has been modified since it was last saved.
PathName: Gets the full path and file name of the document.
ProjectInformation: Gets the Autodesk.Revit.DB.ProjectInfo object associated with the document.
Title: Gets or sets the title of the document.
View: Gets or sets the current view of the document.
Create: Creates a new Revit document.
GetElement: Gets the Element object with the specified ElementId from the document.
GetElementSet: Gets a set of Element objects that meet certain criteria from the document.
Print: Prints the document.
Save: Saves the document.
SaveAs: Saves a copy of the document with a new file name.
The Document class is used to access and manipulate the Revit model data. It provides access to the elements, views, and settings of the model, and provides methods for printing, saving, and creating new documents.
When using the Document class, it is important to be aware of the current application context. Some properties and methods will only work in certain contexts, such as when a view is active or when a certain type of element is selected.
The following code demonstrates how to create a new document and add a wall to it:
// create a new document
Document doc = new Document();
// start a transaction
Transaction t = new Transaction(doc, "Add Wall");
t.Start();
// create a wall
Wall wall = Wall.Create(doc, Line.CreateBound(new XYZ(0, 0, 0), new XYZ(10, 0, 0)), Level.Create(doc, 0));
doc.Regenerate();
// commit the transaction
t.Commit();
// save the document
doc.SaveAs("C:\\temp\\NewDocument.rvt");
// close the document
doc.Close();
This code creates a new document, starts a transaction, adds a wall, saves the document, and closes it. It demonstrates the basic usage of the Document class in creating and manipulating a Revit model.