Manage Worksets of a Link

Manage Worksets of a Link

Anonymous
Not applicable
2,628 Views
11 Replies
Message 1 of 12

Manage Worksets of a Link

Anonymous
Not applicable

Does anyone know if its possible to get (and set) the Opened property of a Workset in a Linked File via API?  In the UI, this is Manage Links > Manage Worksets button.   (Image attached.)  I would like to create a tool that shows this property of all links in a model.  Thanks.

0 Likes
Accepted solutions (1)
2,629 Views
11 Replies
Replies (11)
Message 2 of 12

Charles.Piro
Advisor
Advisor
Accepted solution

Hi,

 

you can access on linkked workset like this :

 

foreach (Document _linkdoc in app.Documents)
                {
                    if (!_linkdoc.IsLinked)
                        continue;
                    WorksetTable _worksetTable = _linkdoc.GetWorksetTable();
                    IList<WorksetPreview> lstPreview =  WorksharingUtils.GetUserWorksetInfo(_linkdoc.GetWorksharingCentralModelPath());
                    foreach (WorksetPreview item in lstPreview)
                    {
                        Workset wkset = _worksetTable.GetWorkset(item.Id);
                        TaskDialog.Show("rvt", wkset.Name);
                    }
                }

 

Smiley Wink



PIRO Charles
Developer

PIRO CIE
Linkedin


Message 3 of 12

Anonymous
Not applicable

Thanks so much!  I modified slightly to create a single dialog.  My implementation:

 

public void GetLinkedWorksets()
		{
			Autodesk.Revit.ApplicationServices.Application app = this.ActiveUIDocument.Application.Application;
			
			string info = "";
			foreach (Document _linkdoc in app.Documents)
            {
				info += _linkdoc.Title + Environment.NewLine;
				
                if (!_linkdoc.IsLinked)
                    continue;
                WorksetTable _worksetTable = _linkdoc.GetWorksetTable();
                IList<WorksetPreview> lstPreview =  WorksharingUtils.GetUserWorksetInfo(_linkdoc.GetWorksharingCentralModelPath());
                foreach (WorksetPreview item in lstPreview)
                {
                    Workset wkset = _worksetTable.GetWorkset(item.Id);
                    
                    if (wkset.IsOpen)
                    	info += wkset.Name + ": Open" + Environment.NewLine;
                    else
                    	info += wkset.Name + ": Closed" + Environment.NewLine;
                }
                
                info += Environment.NewLine;
            }
			
			TaskDialog.Show("Info", info);
		}

Now to figure out if i can set the property using WorksetConfiguration.Close() and Open() methods.

0 Likes
Message 4 of 12

Charles.Piro
Advisor
Advisor

Hi, 

 

you can open or close workset like this :

 

public Result Execute(ExternalCommandData extCmdData, ref string msg, ElementSet elmtSet)
        {
            UIApplication uiapp = extCmdData.Application;
            UIDocument uiDoc = uiapp.ActiveUIDocument;
            Application app = uiapp.Application;
            Document doc = uiDoc.Document;

            try
            {
                List<WorksetId> lstWkSet_Open;
                List<WorksetId> lstWkSet_Close;
                List<Element> lstRvtLinkType = new FilteredElementCollector(doc).OfClass(typeof(RevitLinkType)).ToList();

                foreach (Document _linkdoc in app.Documents)
                {
                    if (!_linkdoc.IsLinked)
                        continue;
                    RevitLinkType _RvtLinkType = null;

                    foreach (Element elmnt in lstRvtLinkType)
                    {
                        _RvtLinkType = elmnt as RevitLinkType;
                        if (_RvtLinkType.Name != _linkdoc.Title)
                            continue;
                        else
                            break;    
                    }

                    lstWkSet_Close = new List<WorksetId>();
                    // Or lstWkSet_Open = new List<WorksetId>();

                    WorksetConfiguration wk = new WorksetConfiguration();
                    ModelPath _modelpath = _linkdoc.GetWorksharingCentralModelPath();
                    WorksetTable _worksetTable = _linkdoc.GetWorksetTable();
                    IList<WorksetPreview> lstPreview = WorksharingUtils.GetUserWorksetInfo(_modelpath);

                    foreach (WorksetPreview item in lstPreview)
                    {
                        Workset wkset = _worksetTable.GetWorkset(item.Id);
                        if (!wkset.IsOpen)
                        {
                            lstWkSet_Close.Add(wkset.Id);
                            continue;
                        }

                        // Or :
                        //if (wkset.IsOpen)
                        //{
                        //    lstWkSet_Open.Add(wkset.Id);
                        //    continue;
                        //}
                    }
                    _RvtLinkType.LoadFrom(_modelpath, wk);
                }

            }
            catch (Exception e)
            {
                msg = e.Message;
                return Result.Failed;
            }
            return Result.Succeeded;
        }
    }

Smiley Wink



PIRO Charles
Developer

PIRO CIE
Linkedin


Message 5 of 12

Anonymous
Not applicable
Charles, Thanks but I can't seem to make this code work. You don't seem to be using WorksetConfiguration.Close() method anywhere. I tried adding it to my version and it still won't close for some reason.
0 Likes
Message 6 of 12

Charles.Piro
Advisor
Advisor

Hi,

 

I forget one line at the end !!!

 

List<WorksetId> lstWkSet_Open;
                List<WorksetId> lstWkSet_Close;
                List<Element> lstRvtLinkType = new FilteredElementCollector(doc).OfClass(typeof(RevitLinkType)).ToList();

                foreach (Document _linkdoc in app.Documents)
                {
                    if (!_linkdoc.IsLinked)
                        continue;
                    RevitLinkType _RvtLinkType = null;

                    foreach (Element elmnt in lstRvtLinkType)
                    {
                        _RvtLinkType = elmnt as RevitLinkType;
                        if (_RvtLinkType.Name != _linkdoc.Title)
                            continue;
                        else
                            break;
                    }

                    lstWkSet_Close = new List<WorksetId>();
                    // Or lstWkSet_Open = new List<WorksetId>();

                    WorksetConfiguration wk = new WorksetConfiguration();
                    ModelPath _modelpath = _linkdoc.GetWorksharingCentralModelPath();
                    WorksetTable _worksetTable = _linkdoc.GetWorksetTable();
                    IList<WorksetPreview> lstPreview = WorksharingUtils.GetUserWorksetInfo(_modelpath);

                    foreach (WorksetPreview item in lstPreview)
                    {
                        Workset wkset = _worksetTable.GetWorkset(item.Id);
                        if (!wkset.IsOpen)
                        {
                            lstWkSet_Close.Add(wkset.Id);
                            continue;
                        }

                        // Or :
                        //if (wkset.IsOpen)
                        //{
                        //    lstWkSet_Open.Add(wkset.Id);
                        //    continue;
                        //}
                    }
                    wk.Open(lstWkSet_Close);
                    //or
                    //wk.Close(lstWkSet_Open);
                    _RvtLinkType.LoadFrom(_modelpath, wk);
                }

Smiley Wink



PIRO Charles
Developer

PIRO CIE
Linkedin


Message 7 of 12

Rockit_for_Revit
Advocate
Advocate

I am trying to do the same thing but close the worksets. When I run my command Revit reloads the link but all the worksets remain open.

 

                                Dim objWorksetTable As WorksetTable = linkedDoc.GetWorksetTable()
                                Dim objModelPath As ModelPath = linkedDoc.GetWorksharingCentralModelPath()
                                Dim lstPreview As IList(Of WorksetPreview) = WorksharingUtils.GetUserWorksetInfo(objModelPath)
                                Dim lstWkSet_Close As New List(Of WorksetId)
                                For Each objWorksetPreview As WorksetPreview In lstPreview
                                    Dim wkset As Workset = objWorksetTable.GetWorkset(objWorksetPreview.Id)
                                    If wkset.IsOpen Then
                                        lstWkSet_Close.Add(wkset.Id)
                                    End If
                                Next
                                Dim wk As WorksetConfiguration = New WorksetConfiguration
                                wk.Close(lstWkSet_Close)
                                objRevitLinkType.LoadFrom(objModelPath, wk)

Kind Regards

David

 

Message 8 of 12

PerryLackowski
Advocate
Advocate

I am encountering the same problem. Did you ever find a solution?

0 Likes
Message 9 of 12

jeremy_tammik
Alumni
Alumni

I asked the development team for you...

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 10 of 12

Rockit_for_Revit
Advocate
Advocate

Kind of,

I ended up using this:

RevitLinkType.LoadFrom(objExternalResourceReference, WorksetConfiguration)

 

Kind Regards

David

 

0 Likes
Message 11 of 12

PerryLackowski
Advocate
Advocate

I figured it out in this similar post.

 

You need to construct the WorksetConfiguration like this to close worksets.

        workset_config = WorksetConfiguration(WorksetConfigurationOption.CloseAllWorksets)
        workset_config.Open(open_this_list_of_worksets)

I originally tried the code below, and it did not work - it left all the Worksets open. Seems like maybe a bug? That or the API just isn't clearly explaining how the WorksetConfiguration Class works...

        workset_config = WorksetConfiguration(WorksetConfigurationOption.OpenAllWorksets)
        workset_config.Close(close_this_list_of_worksets)

So to close Worksets, you need to create a list of the Worksets that you want to remain open.

0 Likes
Message 12 of 12

jeremy_tammik
Alumni
Alumni

This vaguely matches the development team's guess, which says:

  

I think you need to couple the workset unloading with a reload operation by using RevitLinkType.ReloadFrom( path, WorksetConfiguration ) that will let you specify the list of worksets which should be open after the load.

   

The similarity lies in the words 'specify the list of worksets which should be open'...

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes