Create Method (Document, ModelPath, RevitLinkOptions)


Creates a new Revit link type and loads the linked document.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 23.0.0.0 (23.1.0.0)
Since: 2013

Syntax

C#
public static LinkLoadResult Create(
	Document document,
	ModelPath path,
	RevitLinkOptions options
)
Visual Basic
Public Shared Function Create ( _
	document As Document, _
	path As ModelPath, _
	options As RevitLinkOptions _
) As LinkLoadResult
Visual C++
public:
static LinkLoadResult^ Create(
	Document^ document, 
	ModelPath^ path, 
	RevitLinkOptions^ options
)

Parameters

document
Type: Autodesk.Revit.DB Document
The document in which to create the Revit link.
path
Type: Autodesk.Revit.DB ModelPath
The path of the link to load. This may be a path of local disk, Revit Server or Cloud. This must be a full path.
options
Type: Autodesk.Revit.DB RevitLinkOptions
An options class for loading Revit links.

Return Value

An object containing the results of creating and loading the Revit link type. It contains the ElementId of the new link.

Remarks

This function regenerates the input document. While the options argument allows specification of a path type, the input path argument must be a full path. Relative vs. absolute determines how Revit will store the path, but it needs a complete path to find the linked document initially.

Examples

Copy C#
public ElementId CreateRevitLink(Document doc, string pathName)
{
    FilePath path = new FilePath(pathName);
    RevitLinkOptions options = new RevitLinkOptions(false);
    // Create new revit link storing absolute path to a file
    LinkLoadResult result = RevitLinkType.Create(doc, path, options);
    return (result.ElementId);
}
Copy VB.NET
Public Function CreateRevitLink(doc As Document, pathName As String) As ElementId
   Dim path As New FilePath(pathName)
   Dim options As New RevitLinkOptions(False)
   ' Create new revit link storing absolute path to a file
   Dim result As LinkLoadResult = RevitLinkType.Create(doc, path, options)
   Return (result.ElementId)
End Function

Exceptions

Exception Condition
Autodesk.Revit.Exceptions ArgumentException document is not a project document. -or- Server paths cannot be relative. -or- document already contains a linked model at path path. -or- The path to be linked in is empty. -or- The input path "path" does not represent a Revit model.
Autodesk.Revit.Exceptions ArgumentNullException A non-optional argument was null
Autodesk.Revit.Exceptions FileAccessException The model cannot be accessed due to lack of access privileges.
Autodesk.Revit.Exceptions FileNotFoundException The path to be linked in doesn't exist.
Autodesk.Revit.Exceptions InvalidOperationException The model is not allowed to access. -or- Revit cannot customize worksets for this model. -or- Revit cannot link a cloud model to non-cloud model.
Autodesk.Revit.Exceptions ModificationForbiddenException The document is in failure mode: an operation has failed, and Revit requires the user to either cancel the operation or fix the problem (usually by deleting certain elements). -or- The document is being loaded, or is in the midst of another sensitive process.
Autodesk.Revit.Exceptions ModificationOutsideTransactionException The document has no open transaction.
Autodesk.Revit.Exceptions RevitServerInternalException Could be for any of the reasons that failed on service side.
Autodesk.Revit.Exceptions RevitServerUnauthenticatedUserException User is not signed in with Autodesk id.
Autodesk.Revit.Exceptions RevitServerUnauthorizedException User is not authorized to access the specified cloud model.

See Also