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

Hi,
I’m fairly new to revit and I’m having a few issues with the code above.
For context, I’m just trying to relink a revit file, then open up it up and create a new 3D view with all worksets open. This is the last bit that I can’t seem to get working :melting_face:
If I use DB.WorksetConfiguration(DB.WorksetConfigurationOption.OpenAllWorksets) on open, this opens all the worksets, but none off the models shows. If I manually Close and Open them again, the models appear. Not sure why, seems like a bug to me :sweat_smile:
So I thought I’d try and open them after creating the 3D View, but its always giving me a popup saying “No good view” or “wants to check for a good view, might take a while”.
This seems to also only open a few of the worksets, not all of them ? Any help would be great.

Ok, I was able to fix this by using the auto ok for dialogboxes. Just in case anyone else has this issue.

def dismiss(sender, args):
    if isinstance(args, UI.Events.DialogBoxShowingEventArgs):
        args.OverrideResult(1)

# Attach the dialog box showing event handler
__revit__.DialogBoxShowing += dismiss
# use the ShowElements code above to open worksets
__revit__.DialogBoxShowing -= dismiss