Gets the set of worksets to open when creating the link.
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 2015.0.0.0 (2015.0.0.0)
Since: 2014
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
Examples

public bool CreateRevitLinkWithOneWorksetOpen(Document doc, string pathName, string worksetName)
{
FilePath path = new FilePath(pathName);
RevitLinkOptions options = new RevitLinkOptions(true);
// Get info on all the user worksets in the project prior to opening
IList<WorksetPreview> worksets = WorksharingUtils.GetUserWorksetInfo(path);
IList<WorksetId> worksetIds = new List<WorksetId>();
// Find worksetName
foreach (WorksetPreview worksetPrev in worksets)
{
if (worksetPrev.Name.CompareTo(worksetName) == 0)
{
worksetIds.Add(worksetPrev.Id);
break;
}
}
// close all worksets but the one specified
WorksetConfiguration worksetConfig = new WorksetConfiguration(WorksetConfigurationOption.CloseAllWorksets);
if (worksetIds.Count > 0)
{
worksetConfig.Open(worksetIds);
}
options.SetWorksetConfiguration(worksetConfig);
RevitLinkLoadResult result = RevitLinkType.Create(doc, path, options);
RevitLinkType type = doc.GetElement(result.ElementId) as RevitLinkType;
return (result.LoadResult == RevitLinkLoadResultType.LinkLoaded);
}

Public Function CreateRevitLinkWithOneWorksetOpen(doc As Document, pathName As String, worksetName As String) As Boolean
Dim path As New FilePath(pathName)
Dim options As New RevitLinkOptions(True)
' Get info on all the user worksets in the project prior to opening
Dim worksets As IList(Of WorksetPreview) = WorksharingUtils.GetUserWorksetInfo(path)
Dim worksetIds As IList(Of WorksetId) = New List(Of WorksetId)()
' Find worksetName
For Each worksetPrev As WorksetPreview In worksets
If worksetPrev.Name.CompareTo(worksetName) = 0 Then
worksetIds.Add(worksetPrev.Id)
Exit For
End If
Next
' close all worksets but the one specified
Dim worksetConfig As New WorksetConfiguration(WorksetConfigurationOption.CloseAllWorksets)
If worksetIds.Count > 0 Then
worksetConfig.Open(worksetIds)
End If
options.SetWorksetConfiguration(worksetConfig)
Dim result As RevitLinkLoadResult = RevitLinkType.Create(doc, path, options)
Dim type As RevitLinkType = TryCast(doc.GetElement(result.ElementId), RevitLinkType)
Return (result.LoadResult = RevitLinkLoadResultType.LinkLoaded)
End Function