<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to open/close workset in a linked revit programmatically in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-open-close-workset-in-a-linked-revit-programmatically/m-p/10593102#M43520</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have you tried with the model path accessed below?&lt;/P&gt;&lt;LI-CODE lang="general"&gt;ModelPath mpath = link_instance.GetLinkDocument().GetCloudModelPath()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.revitapidocs.com/2022/087a7c14-1a6e-7022-c47b-923e90f4c5be.htm" target="_blank" rel="noopener"&gt;https://www.revitapidocs.com/2022/087a7c14-1a6e-7022-c47b-923e90f4c5be.htm&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Sep 2021 09:27:45 GMT</pubDate>
    <dc:creator>tamas.deri</dc:creator>
    <dc:date>2021-09-02T09:27:45Z</dc:date>
    <item>
      <title>How to open/close workset in a linked revit programmatically</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-open-close-workset-in-a-linked-revit-programmatically/m-p/8677359#M43517</link>
      <description>&lt;P&gt;I am trying to open/close worksets in a linked revit. I can't change the workset.Isopen because it is readonly.&lt;/P&gt;
&lt;P&gt;Anybody has an idea,&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 15:59:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-open-close-workset-in-a-linked-revit-programmatically/m-p/8677359#M43517</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-03-22T15:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to open/close workset in a linked revit programmatically</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-open-close-workset-in-a-linked-revit-programmatically/m-p/10471085#M43518</link>
      <description>&lt;P&gt;Here's a complete solution for PyRevit as of 2020.1. The API does not have an easy way to set a workset open or closed - instead you need to reload the link with a new workset configuration. This means creating a workset configuration that defaults to closing all worksets, then loading it up with all the worksets you want to remain open. Then you pass this into the LoadFrom method to reload the link.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;'''
Goes to Manage &amp;gt; Manage Links &amp;gt; Manage Worksets and opens the Shared Levels and Grids workset for each LOADED link.

TESTED REVIT API: 2020

Author: Robert Perry Lackowski

'''
from pyrevit import DB
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB import FilteredElementCollector
from Autodesk.Revit.DB import Transaction
from Autodesk.Revit.DB import WorksharingUtils
from Autodesk.Revit.DB import WorksetConfiguration
from Autodesk.Revit.DB import RevitLinkType
from Autodesk.Revit.UI import TaskDialog

from pyrevit import script
output = script.get_output()

import traceback

doc = __revit__.ActiveUIDocument.Document
app = __revit__.ActiveUIDocument.Application.Application

# Set the name of the workset you would like to hide. Decide if you want to hide it or unhide it.
hide_this_workset = "Shared Levels and Grids"
hide_workset = False

for link_doc in app.Documents:
    
    link_doc_title = link_doc.Title
    print link_doc_title

    # Exclude the project file itself
    if not link_doc.IsLinked:
        print "this one isn't linked, skip the rest of the for loop \n\n "
        continue
    
    # Get a list of the RevitLinkType elements in the active document.
    revit_link_types = FilteredElementCollector(doc).OfClass(DB.RevitLinkType).ToElements()
 
    # This finds the RevitLinkType element that matches the link_doc.
    rlt = next((rlt for rlt in revit_link_types if rlt.LookupParameter("Type Name").AsString().rstrip(".rvt") == link_doc_title), None)
    if not rlt:
        print "No matching RevitLinkType for the link_doc."
    else:
        temp = "Updating workset visibility on this file: " + str(link_doc.Title)
        print temp

        # generate a list of the worksets in the link_doc
        workset_table = link_doc.GetWorksetTable()
        model_path = link_doc.GetWorksharingCentralModelPath()
        lst_preview = WorksharingUtils.GetUserWorksetInfo(model_path)

        # Populate list of worksets to enable
        open_this_list_of_worksets = []
        
        for objWorksetPreview in lst_preview:
            wkset = workset_table.GetWorkset(objWorksetPreview.Id)
            
            if hide_workset:
                #gather a list of all the open worksets, EXCLUDING the workset we want to hide
                if wkset.IsOpen and (wkset.Name != hide_this_workset):
                    open_this_list_of_worksets.append(wkset.Id)
            else:
                #gather a list of all the open worksets, INCLUDING the one we hid.
                if wkset.IsOpen or wkset.Name == hide_this_workset:
                    open_this_list_of_worksets.append(wkset.Id)
        
        # Set the WorksetConfiguration file to close all worksets, then open the ones from the list
        workset_config = WorksetConfiguration(WorksetConfigurationOption.CloseAllWorksets)
        workset_config.Open(open_this_list_of_worksets)
        
        #reload the link with the updated workset configuration
        rlt.LoadFrom(model_path, workset_config)
        
        #delete the workset configuration after use
        workset_config.Dispose()

print "Script complete."&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jul 2021 13:09:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-open-close-workset-in-a-linked-revit-programmatically/m-p/10471085#M43518</guid>
      <dc:creator>PerryLackowski</dc:creator>
      <dc:date>2021-07-15T13:09:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to open/close workset in a linked revit programmatically</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-open-close-workset-in-a-linked-revit-programmatically/m-p/10592873#M43519</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2186426"&gt;@PerryLackowski&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was trying this solution but it does not work since most of out projects are on Bim360.&amp;nbsp;&lt;/P&gt;&lt;P&gt;the &lt;EM&gt;&lt;STRONG&gt;WorksharingUtils.GetUserWorksetInfo&lt;/STRONG&gt;&lt;/EM&gt; does not take a cloud path and throws an Exception :&amp;nbsp;&lt;/P&gt;&lt;DIV class="errorentry"&gt;&lt;EM&gt;Autodesk.Revit.Exceptions.ArgumentException: The given path path is a cloud path which is not supported in this method. (see here -&amp;nbsp;&lt;A href="https://www.revitapidocs.com/2021.1/15ec1e3e-61d5-b6a1-3604-8b866a988270.htm" target="_blank"&gt;https://www.revitapidocs.com/2021.1/15ec1e3e-61d5-b6a1-3604-8b866a988270.htm&lt;/A&gt;)&lt;/EM&gt;&lt;/DIV&gt;&lt;P&gt;I&amp;nbsp; wondering if you have any idea how to get this to work if the Links are cloud path ?&lt;/P&gt;&lt;P&gt;Thanks , Jonathan .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 08:02:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-open-close-workset-in-a-linked-revit-programmatically/m-p/10592873#M43519</guid>
      <dc:creator>MYS-JonathanT</dc:creator>
      <dc:date>2021-09-02T08:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to open/close workset in a linked revit programmatically</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-open-close-workset-in-a-linked-revit-programmatically/m-p/10593102#M43520</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have you tried with the model path accessed below?&lt;/P&gt;&lt;LI-CODE lang="general"&gt;ModelPath mpath = link_instance.GetLinkDocument().GetCloudModelPath()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.revitapidocs.com/2022/087a7c14-1a6e-7022-c47b-923e90f4c5be.htm" target="_blank" rel="noopener"&gt;https://www.revitapidocs.com/2022/087a7c14-1a6e-7022-c47b-923e90f4c5be.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 09:27:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-open-close-workset-in-a-linked-revit-programmatically/m-p/10593102#M43520</guid>
      <dc:creator>tamas.deri</dc:creator>
      <dc:date>2021-09-02T09:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to open/close workset in a linked revit programmatically</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-open-close-workset-in-a-linked-revit-programmatically/m-p/13276980#M43521</link>
      <description>&lt;P&gt;Still no solution for this? I am trying to open worksets from model in ACC?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 22:50:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-open-close-workset-in-a-linked-revit-programmatically/m-p/13276980#M43521</guid>
      <dc:creator>alfredior</dc:creator>
      <dc:date>2025-01-22T22:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to open/close workset in a linked revit programmatically</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-open-close-workset-in-a-linked-revit-programmatically/m-p/13299536#M43522</link>
      <description>&lt;P&gt;Welcome to the club.&lt;BR /&gt;I too am trying to open a cloud model and manage the opened/closed worksets.&lt;BR /&gt;So I see that&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;WorksharingUtils.GetUserWorksetInfo&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;does not work with CloudPath indeed.&lt;BR /&gt;So the only option is to open the document and tinker with the worksets after.&lt;BR /&gt;But... there seems to be no way to open or close a workset within an opened document (which seems really odd)?!??&lt;/P&gt;&lt;P&gt;Anyone has a lead on that?&lt;BR /&gt;I tried&amp;nbsp;workset.IsOpen = True but the property is read only.&lt;BR /&gt;Various AI tools systematically assume that&amp;nbsp;WorksetTable.SetOpen method exist (but it doesn't).&lt;BR /&gt;So I'm stuck with the dilemma of managing all my cloud models using&amp;nbsp;&lt;BR /&gt;WorksetConfigurationOption.OpenAllWorksets or&amp;nbsp; WorksetConfigurationOption.CloseAllWorksets&lt;BR /&gt;Help...&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2025 18:02:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-open-close-workset-in-a-linked-revit-programmatically/m-p/13299536#M43522</guid>
      <dc:creator>richard.laroche</dc:creator>
      <dc:date>2025-02-04T18:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to open/close workset in a linked revit programmatically</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-open-close-workset-in-a-linked-revit-programmatically/m-p/13299698#M43523</link>
      <description>&lt;P&gt;The pyrevit code I posted above was the only way I have found to manipulate the worksets. But yes, it does require setting the configuration before reloading the link.&lt;/P&gt;&lt;P&gt;If that's not working with cloud model paths we may need to call in the big guns. &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/413917"&gt;@jeremytammik&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2025 19:09:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-open-close-workset-in-a-linked-revit-programmatically/m-p/13299698#M43523</guid>
      <dc:creator>PerryLackowski</dc:creator>
      <dc:date>2025-02-04T19:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to open/close workset in a linked revit programmatically</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/how-to-open-close-workset-in-a-linked-revit-programmatically/m-p/13300383#M43524</link>
      <description>&lt;P&gt;Same problem. Looks like the only way of doing this is to open ALL the models from the beginning. No other way until now.&lt;/P&gt;&lt;P&gt;Thanks for replying&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2025 02:34:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/how-to-open-close-workset-in-a-linked-revit-programmatically/m-p/13300383#M43524</guid>
      <dc:creator>alfredior</dc:creator>
      <dc:date>2025-02-05T02:34:21Z</dc:date>
    </item>
  </channel>
</rss>

