Document stores the Revit Elements, manages the data, and updates multiple data views. The Document class mainly provides the following functions.
The Document class represents an open Autodesk Revit project.
The Settings property returns an object that provides access to general components within Revit projects. For more details, see Settings.
Each project has only one site location that identifies the physical project location on Earth. There can be several project locations for one project. Each location is an offset, or rotation, of the site location. For more details, see Place and Locations.
A project document can have multiple views. The ActiveView property returns a View object representing the active view. You can filter the elements in the project to retrieve other views. For more details, see Views.
The Document object stores elements in the project. Retrieve specific elements by ElementId or UniqueId using the Element property.
For more details, see Elements Essential.
Each Document object represents a Revit project file. Document provides the following functions:
For more details, see Document and File management.
Revit maintains all Element objects in a project. To create new elements, use the Create property which returns an Object Factory used to create new project element instances in the Revit Platform API, such as FamilyInstance or Group.
The Document class can also be used to delete elements. Use the Delete() method to delete an element in the project. Deleted elements and any dependent elements are not displayed and are removed from the Document. References to deleted elements are invalid and cause an exception. For more details, see Editing Elements.
Events are raised on certain actions, such as when you save a project using Save or Save As. To capture the events and respond in the application, you must register the event handlers. For more details, see Events.
Several properties provide information on the status of the document:
Document also provides other functions:
The UIDocument class represents an Autodesk Revit project opened in the Revit user interface.
Retrieve selected elements using the Selection property in UIDocument. This property returns an object representing the active selection containing the selected project elements. It also provides UI interaction methods to pick objects in the Revit model.
For more details, see Elements Essentials.
The ShowElements() method uses zoom to fit to focus in on one more elements.
The UIDocument class can be used to refresh the active view in the active document by calling the RefreshActiveView() method. The ActiveView property can be used to retrieve or set the active view for the document. Changing the active view has some restrictions. It can only be used in an active document, which must not be in read-only state and must not be inside a transaction. Additionally, the active view may not be changed during the ViewActivating or ViewActivated event, or during any pre-action event, such as DocumentSaving, DocumentClosing, or other similar events.
The UIDocument.ActiveGraphicalView property retrieves the active graphical view for the document. Unlike UIDocument.ActiveView, this property will never return auxiliary views like the Project Browser or System Browser if the user has happened to make a selection in one of those views.
The UIDocument can also be used to get a list of all open view windows in the Revit user interface. The GetOpenUIViews method returns a list of UIViews which contain data about the view windows in the Revit user interface.