Open selected Worksets

Hi, is there any way to open Worksets when Revit model has been already opened?

The revitapidocs says about WorksetConfiguration:

the methods of this class just adjust the specification, and do not themselves open or close worksets.

But is there any way how to apply this specification to the project/model to actually open the Worksets?
This is my attempt - doesn’t work for me of course :slight_smile:
Thanks!

from Autodesk.Revit import DB

doc = __revit__.ActiveUIDocument.Document

if doc.IsWorkshared:
    ws_collector = DB.FilteredWorksetCollector(doc)\
                     .OfKind(DB.WorksetKind.UserWorkset)
    ws_ids = []
    for ws in ws_collector:
        if "link" not in ws.Name.lower():
            ws_ids.append(ws.Id)

    t = DB.Transaction(doc, "Open Non Link Worksets")
    t.Start()

    ws = DB.WorksetConfiguration()
    ws.Open(ws_ids)

    t.Commit()

Hi @davidvadkerti
that should help ApiDocs.co
and especially this https://github.com/gtalarico/revitapidocs.code/blob/master/0-python-code/HowTo_ChangeWorksetSetting.py
all by the same person: Gui Talarico

"""
Change Workset Settings
Set workset to be hidden by default in all views

TESTED REVIT API: 2017

Author: Gui Talarico | github.com/gtalarico

This file is shared on www.revitapidocs.com
For more information visit http://github.com/gtalarico/revitapidocs
License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md
"""

import clr
clr.AddReference("RevitAPI")

from Autodesk.Revit.DB import Transaction, WorksetKind, FilteredWorksetCollector
from Autodesk.Revit.DB import WorksetDefaultVisibilitySettings

doc = __revit__.ActiveUIDocument.Document

# collect all worksets
worksets = FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset)

# iterate over  worksets
for workset in worksets:
    # Find workset you want to target by name
    if workset.Name == 'Replace this with Name of Workset to Target':
        t = Transaction(doc)
        t.Start('Hide Workset in all Views')

        defaultVisibility = WorksetDefaultVisibilitySettings.GetWorksetDefaultVisibilitySettings(doc)
        defaultVisibility.SetWorksetVisibility(workset.Id, False)

        t.Commit()

and this too

Thanks @Jean-Marc, Yesterday I found both approaches though from a different source. If I am not missing something they do not do what I want to achieve.

  • 1st example is changing Default Workset Visibility - I don’t want to do this, this time :slight_smile:
  • 2nd example is doing what I want to achieve but with Worksets of Linked RVT models. As I get it Workset Opened/Closed status is written by LoadFrom(). I would like to do this not with links but the main host model.

My goal is to open Worksets (magenta column) not to Change its Default visibility (Azure column - this is what your second example does)


I want to open the model with all Worksets closed and then open just the Worksets without “link” in their name to improve performance in Revit Batch Processor Script. Everything works, Worksets are filtered out correctly but their Opened/Closed status is not changed at all.

Thanks :slight_smile:

1 Like

Check the last point :smiley:
Open closed worksets in open document? - Autodesk Community

2 Likes

This is awesome! Thanks!
This is my solution for now.

from Autodesk.Revit import DB
from Autodesk.Revit.DB.Document import GetElement

doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument

if doc.IsWorkshared:
    ws_collector = DB.FilteredWorksetCollector(doc)\
                     .OfKind(DB.WorksetKind.UserWorkset)\
                     .ToWorksets()

    for ws in ws_collector:
        if "link" not in ws.Name.lower():
            # get all elements in a workset
            filter = DB.ElementWorksetFilter(ws.Id)
            ws_elems = DB.FilteredElementCollector(doc)\
                         .WherePasses(filter)\
                         .WhereElementIsNotElementType()\
                         .ToElements()
            if ws_elems:
                # get first element in a workset
                first_elem_id = ws_elems[0].Id
                uidoc.ShowElements(doc.GetElement(first_elem_id)) 
2 Likes