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: 19.0.0.0 (19.0.0.405)
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 server path. 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 given path path is a cloud path which is not supported in this method. -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 FileArgumentNotFoundException There is not a valid Revit file at path's location
Autodesk.Revit.Exceptions InvalidOperationException Revit cannot customize worksets for this 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.

See Also