Skip to content

RevitLinkType.Create(Document, ModelPath, RevitLinkOptions)

Public Class

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

Namespace: Autodesk.Revit.DB

Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)

Syntax

public static LinkLoadResult Create(
Document document,
ModelPath path,
RevitLinkOptions options
)

Parameters

document Document

The document in which to create the Revit link.

path 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 RevitLinkOptions

An options class for loading Revit links.

Return Value

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

Exceptions

Exception

Condition


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.


ArgumentNullException

A non-optional argument was null


FileAccessException

The model cannot be accessed due to lack of access privileges.


FileNotFoundException

The path to be linked in doesn’t exist.


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.


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.


ModificationOutsideTransactionException

The document has no open transaction.


RevitServerInternalException

Could be for any of the reasons that failed on service side.


RevitServerUnauthenticatedUserException

User is not signed in with Autodesk id.


RevitServerUnauthorizedException

User is not authorized to access the specified cloud model.


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.

Example

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);
}