How to open Revit model with unload Revit links option

How to open Revit model with unload Revit links option

archana.sapkal
Participant Participant
911 Views
4 Replies
Message 1 of 5

How to open Revit model with unload Revit links option

archana.sapkal
Participant
Participant

Autodesk.Revit.DB.Document doc11 = uiapp.Application.OpenDocumentFile(model Path, open Options);

here how can OpenDocument with unload Revit links ?

0 Likes
912 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Alumni
Alumni

Yes, you can achieve this using the transmission data:

   

   

Here are some old notes from another case on closing worksets and unloading links when opening model:

  

Q: Can worksets be closed or links unloaded programmatically without actually opening the RVT model?
A developer asks: System memory is hitting the limit. My Add-in does not need the Revit Links to be loaded to be able to function. Can I somehow open the RVT file with

  • (1) all worksets closed or
  • (2) all RVT links unloaded

to save system memory? Is there a way to achieve this in the APS design automation activity command line?

  

A: I have two samples demonstrating how to open a RVT file with worksets closed / RVT links unloaded, but I haven’t migrated them to DA4R.

  

Q: Just to confirm - you change this on the fly, you do not need to save the file for not loading those on next load? by mean if you need to load the file to change the settings for the next load, that does not help. So is it for next time, or does it disable loading on the fly? I ask, because the comment says 'next time': This method will set all Revit links to be unloaded the next time the document at the given location is opened.

  

A: the command to open the model with worksets closed just sets a property in the OpenOptions SetOpenWorksetsConfiguration. it then calls OpenAndActivateDocument to open the model with worksets closed. so, this is only valid for the lifetime of the OpenOptions and the open call needs to be executed immediately. The command to not load links is different: for that, an option is set and stored in the model transmission data using TransmissionData.WriteTransmissionData. In that case, the option will be remembered and applied next time an open is performed. in the sample command, an open follows immediately. however, it could also be executed later, and the setting would be retained. So, the two methods can both be used to disable loading on the fly, provided the caller does the opening. I hardly think the workset config option can be controlled in this manner by the default design automation environment. However, in DA, the file to open could be passed in as payload, and the DA add-in could implement the call to open the file itself, couldn't it?

  
... I spent some time to verify if the changes remain in the file after closing Revit. As said, TransmissionData.WriteTransmissionData will store the link unload state in the RVT file. But, if a customer wants to keep workset state, they must call Document#SaveAs to save the changes made.

    

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

archana.sapkal
Participant
Participant

public static Result UnloadRevitLinks(string filePath)
{
FilePath location = new FilePath(filePath);
TransmissionData transData = TransmissionData.ReadTransmissionData(location);
try
{
if (transData != null)
{
ICollection<ElementId> externalReferences = transData.GetAllExternalFileReferenceIds();
MessageBox.Show("externalReferences" + externalReferences);
foreach (ElementId refId in externalReferences)
{
MessageBox.Show("refId" + refId);
ExternalFileReference extRef = transData.GetLastSavedReferenceData(refId);
MessageBox.Show("extRef" + extRef);
if (extRef.ExternalFileReferenceType == ExternalFileReferenceType.RevitLink || extRef.ExternalFileReferenceType == ExternalFileReferenceType.CADLink)
{
MessageBox.Show("Deleteting revit links");
transData.SetDesiredReferenceData(refId, extRef.GetPath(), extRef.PathType, false);
MessageBox.Show("All revit links are deleted");
}
}
transData.IsTransmitted = true;
TransmissionData.WriteTransmissionData(location, transData);
return Result.Succeeded;
}
else
{
TaskDialog.Show("Unload Revit Links", "The document does not have any transmission data.");
return Result.Failed;
}
}
catch (Exception ex)
{
MessageBox.Show("ex" + ex);
throw;

Here how can unload Revit Links as well as CAD links

Message 4 of 5

jeremy_tammik
Alumni
Alumni

Thank you for sharing your solution.

   

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

baleti3266
Advocate
Advocate

have you ever tried editing TransmissionData in .rvt files directly (xml file)? any side effects to watch out for?

0 Likes