GetWorksetConfiguration Method


Gets the set of worksets to open when creating the link.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 18.0.0.0 (18.0.0.420)
Since: 2014

Syntax

C#
public WorksetConfiguration GetWorksetConfiguration()
Visual Basic
Public Function GetWorksetConfiguration As WorksetConfiguration
Visual C++
public:
WorksetConfiguration^ GetWorksetConfiguration()

Examples

Copy C#
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);

    LinkLoadResult result = RevitLinkType.Create(doc, path, options);
    RevitLinkType type = doc.GetElement(result.ElementId) as RevitLinkType;
    return (result.LoadResult == LinkLoadResultType.LinkLoaded);
}
Copy VB.NET
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 LinkLoadResult = RevitLinkType.Create(doc, path, options)
   Dim type As RevitLinkType = TryCast(doc.GetElement(result.ElementId), RevitLinkType)
   Return (result.LoadResult = LinkLoadResultType.LinkLoaded)
End Function

See Also