OpenDocumentFile Method (ModelPath, OpenOptions)


Opens a document from disk or cloud.

Namespace: Autodesk.Revit.ApplicationServices
Assembly: RevitAPI (in RevitAPI.dll) Version: 20.0.0.0 (20.0.0.377)
Since: 2013

Syntax

C#
public Document OpenDocumentFile(
	ModelPath modelPath,
	OpenOptions openOptions
)
Visual Basic
Public Function OpenDocumentFile ( _
	modelPath As ModelPath, _
	openOptions As OpenOptions _
) As Document
Visual C++
public:
Document^ OpenDocumentFile(
	ModelPath^ modelPath, 
	OpenOptions^ openOptions
)

Parameters

modelPath
Type: Autodesk.Revit.DB ModelPath
The file to be opened.
openOptions
Type: Autodesk.Revit.DB OpenOptions
Options for opening the file.

Return Value

The opened document.

Remarks

This method opens the document into memory but does not make it visible to the user in any way.

Examples

Copy C#
private static Document OpenDetached(Application application, ModelPath modelPath)
{
    OpenOptions options1 = new OpenOptions();

    options1.DetachFromCentralOption = DetachFromCentralOption.DetachAndDiscardWorksets;
    Document openedDoc = application.OpenDocumentFile(modelPath, options1);

    return openedDoc;
}
Copy VB.NET
Private Shared Function OpenDetached(application As Application, modelPath As ModelPath) As Document
    Dim options1 As New OpenOptions()

    options1.DetachFromCentralOption = DetachFromCentralOption.DetachAndDiscardWorksets
    Dim openedDoc As Document = application.OpenDocumentFile(modelPath, options1)

    Return openedDoc
End Function

Exceptions

Exception Condition
Autodesk.Revit.Exceptions ArgumentException The modelPath to be opened is empty.
Autodesk.Revit.Exceptions ArgumentNullException A non-optional argument was NULL
Autodesk.Revit.Exceptions CannotOpenBothCentralAndLocalException Cannot open the local model and the central model in the same Revit session. You can close one to open the other in the same Revit session.
Autodesk.Revit.Exceptions CentralModelAccessDeniedException Access to the central model was denied. A possible reason is because the model was under maintenance.
Autodesk.Revit.Exceptions CentralModelContentionException The model on the RevitServer is being accessed by other users. -or- The central model is locked by another client.
Autodesk.Revit.Exceptions CentralModelException Revit encountered serious errors while trying to open the central model. -or- An internal error happened on the central model, please contact the server administrator.
Autodesk.Revit.Exceptions CorruptModelException There are too many corrupt elements to open this model.
Autodesk.Revit.Exceptions FileAccessException File cannot be opened in Revit LT because it was last saved in a version of Revit prior to 8.1. -or- File has an invalid extension. Try changing the file's extension and opening it again. -or- File was saved by an application that was not developed or licensed by Autodesk.
Autodesk.Revit.Exceptions FileNotFoundException The modelPath to be opened doesn't exist. -or- File Not Found
Autodesk.Revit.Exceptions InsufficientResourcesException This computer does not have enough memory, disk space, or other necessary resource to open the model.
Autodesk.Revit.Exceptions InvalidOperationException Open is temporarily disabled. -or- The cloud model is not saved in current release of Revit. -or- The document can not be opened. -or- Revit cannot save the transmitted model as a new central because it is already opened.
Autodesk.Revit.Exceptions OperationCanceledException Opening was canceled by the user or by an API event callback.
Autodesk.Revit.Exceptions RevitServerCommunicationException The server-based central model could not be accessed because of a network communication error.
Autodesk.Revit.Exceptions RevitServerInternalException An internal error happened on the server, please contact the server administrator.
Autodesk.Revit.Exceptions RevitServerUnauthorizedException User is not authorized to access the cloud model.
Autodesk.Revit.Exceptions WrongUserException The local file is not owned by the current user, who therefore is not allowed to modify it.

See Also