Open closed Workset in model

Open closed Workset in model

kevin_fielding
Advocate Advocate
740 Views
11 Replies
Message 1 of 12

Open closed Workset in model

kevin_fielding
Advocate
Advocate

Hi, 

 

I'm processing models to repath Revit links. I open a model with all worksets closed as some models will be very large. 

 

When a RevitLinkType is found and it's path needs updating, I'm unable to use ReloadFrom method as the workset is closed (this is possible in the UI). The api doesn't currently support opening worksets while the model is open, which I think is crazy.  Ideally, I don't want to open all the worksets when I initially open the model as this is unnecessary as a) no links may need repathing, and b) the performance hit. 

 

I've seen a hack where a new element is created in the workset and the ShowElement method is used. This won't work for me as my models aren't UIDocs (again for performance reasons). 

 

https://forums.autodesk.com/t5/revit-api-forum/open-closed-worksets-in-open-document/td-p/6238121

 

Does anyone have any suggestions for a way to open a closed workset when a model is open but not activated?

 

Note - I need to open the model rather than use Transmission data as the models have originated from the cloud and I need to repath links locally (archiving purposes), in this instance cloud link information isn't stored in the Transmission data. 

 

Thanks in advance. 

0 Likes
741 Views
11 Replies
Replies (11)
Message 2 of 12

jeremy_tammik
Alumni
Alumni

Sounds tricky. I asked the development team for you.

 

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

jeremy_tammik
Alumni
Alumni

They say:  Seems like that the desired actions of ‘checking the current path’ and ‘changing the path’ can be performed without even opening the model (so orders of magnitude faster) by utilising the TransmissionData class:

  

https://www.revitapidocs.com/2024/d78d1e9c-1cee-1336-88d5-b605dacd077d.htm

  
Once the path is verified as needing to be updated, and the new path set, the model can be opened with the altered link’s worksets opened (quite easy if the recommended practice of one link per workset, one workset per link was followed) to verify any issues stemming from the repathing.

 

That said, opening/closing worksets of an open document via the API does feel like a gap worth addressing if it can’t currently be done.

  

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

kevin_fielding
Advocate
Advocate

Hi Jeremy, 

 

Thanks for your efforts and reply. 

 

This is the process I am currently undertaking, and it works for all models that are non-cloud hosted. For Cloud models however,  the link information isn't stored within the TransmissionData for these models, hence why I am required to open these models and interrogate them directly. 

 

Even with the updates to the TransmissionData within the models, I'm still required to open and save the models to update the links as the models need to be marked as IsTransmitted. 

 

With regards to updates to the API, two options would work for my scenario, either I can call Reload on the RevitLinkType when it is in a closed worksets (like the UI supports), or I am able to open the workset and reload the link.  The former would be the preferred option for me. 

 

Kind regards,

0 Likes
Message 5 of 12

jeremy_tammik
Alumni
Alumni

I thought their reply sounded too easy... I passed your reply back to them...

  

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

jeremy_tammik
Alumni
Alumni

They say: That seems like a much larger issue and something else which should be addressed. Perhaps due to the way cloud paths are handled?

  

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

kevin_fielding
Advocate
Advocate

In the normal day to day activities for Revit it's not necessary for anything to access TransmissionData, so I doubt it would impact the models, is more the fact that the TransmissionData can't be used to repath models. 

I've further tested this, the only solution that works is opening the model with all worksets open and Reload each one from the new location. Unfortunately as the models still reside in the cloud , Revit still loads the existing links which for a small model with lots of links is a huge performance hit.  While the process for a local model is 30secs-5 mins for a local model this could be 30mins + for a Cloud model. 

 

Obviously, if the TransmissionData can be written in the cloud for the Cloud Links that would be great, but the next best solution for me is to Reload links without having to open any workset.

 

Thanks again for your assistance. 

0 Likes
Message 8 of 12

RPTHOMAS108
Mentor
Mentor

Could try putting link on newly created open workset and then switching back i.e. this works for non cloud models.

 

 Private Function Obj_231218a(ByVal commandData As Autodesk.Revit.UI.ExternalCommandData,
ByRef message As String, ByVal elements As Autodesk.Revit.DB.ElementSet) As Result

        Dim UIApp As UIApplication = commandData.Application
        Dim UIDoc As UIDocument = commandData.Application.ActiveUIDocument
        If UIDoc Is Nothing Then Return Result.Cancelled Else
        Dim Doc As Document = UIDoc.Document

        Dim FEC As New FilteredElementCollector(Doc)
        Dim ECF As New ElementClassFilter(GetType(RevitLinkType))
        Dim LnkTyp As RevitLinkType = FEC.WherePasses(ECF).Where(Function(k) k.Name = "Simple.rvt").FirstOrDefault
        Dim OldId As Integer = LnkTyp.Parameter(BuiltInParameter.ELEM_PARTITION_PARAM).AsInteger

        Dim WSId As WorksetId = Nothing
        Using Tx As New Transaction(Doc, "WS0")
            If Tx.Start = TransactionStatus.Started Then
                Dim WS As Workset = Workset.Create(Doc, "Temp" & Guid.NewGuid.ToString)
                WSId = WS.Id
                LnkTyp.Parameter(BuiltInParameter.ELEM_PARTITION_PARAM).Set(WSId.IntegerValue)

                Tx.Commit()
            End If
        End Using
        If WSId Is Nothing Then
            Return Result.Cancelled
        End If
        Dim WC As New WorksetConfiguration(WorksetConfigurationOption.OpenLastViewed)
        LnkTyp.LoadFrom(ModelPathUtils.ConvertUserVisiblePathToModelPath("C:\RPTTestFolder\2024\SimpleY.rvt"), WC)

        Using Tx As New Transaction(Doc, "WS1")
            If Tx.Start = TransactionStatus.Started Then
                LnkTyp.Parameter(BuiltInParameter.ELEM_PARTITION_PARAM).Set(OldId)
                WorksetTable.DeleteWorkset(Doc, WSId, New DeleteWorksetSettings With {.DeleteWorksetOption = DeleteWorksetOption.DeleteAllElements})
                Tx.Commit()
            End If
        End Using

        Return Result.Succeeded
    End Function

 

Message 9 of 12

kevin_fielding
Advocate
Advocate
Thanks RPTHOMAS108,

That's a good idea, I'll give that a try and report back.

I presume I only have to move the RevitLinkType and not the instances of the Type.
0 Likes
Message 10 of 12

RPTHOMAS108
Mentor
Mentor

I only tested by moving the type I assumed since path is likely only stored in type and that is what is being changed so that is all that matters. For robustness you should probably check perhaps, Revit API has odd rules sometimes. Not even sure what happen if you have an instance that is on an open workset but the type is on a closed one.

Message 11 of 12

kevin_fielding
Advocate
Advocate
The method DeleteWorkset is only available from Revit 2023 onwards, unfortunately one of my test projects for this tool is in Revit 2021.

This should provide a solution for future versions though.
Message 12 of 12

jeremy_tammik
Alumni
Alumni

The Revit development team will take a look at improving this.

  

Trying to find existing solution: The idea of "checking which models need an update, opening with only those worksets, and then repathing those" should help him along for now.

    

  • Open the model with worksets closed.
  • Find links that need repathing.
  • Find the worksets for those links.
  • Close the model.
  • Open the model with worksets that contain the links.
  • Repath the links.
  • Close the model.

    

They should be able to accomplish the 'checking' with the transmission data, as the blocker is that changes to transmission data don't synch back... still checking...

  

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