Message 1 of 3
Update Linked Files Path
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I am trying to update an linked files path in Revit 2014 using a IExternalApplication. This code runs all the way trough with no errors but the link is not changed, It dosen't seem to actually commit the changes, any suggestions please ?
Many thanks in advance
private static void LinksUpdate(ModelPath path, DocRvt doc) { // access transmission data in the given Revit file TransmissionData transData = TransmissionData.ReadTransmissionData(path); if (transData != null) { // collect all (immediate) external references in the model ICollection<ElementId> externalReferences = transData.GetAllExternalFileReferenceIds(); // find every reference that is a link foreach (ElementId refId in externalReferences) { ExternalFileReference extRef = transData.GetLastSavedReferenceData(refId); if (extRef.ExternalFileReferenceType == ExternalFileReferenceType.RevitLink) { bool ShouldLoad; if (extRef.GetLinkedFileStatus().ToString() == "Loaded") { ShouldLoad = true; } else { ShouldLoad = false; } using (Transaction trans = new Transaction(doc, "Links Updater")) { trans.Start(); ModelPath ExsiitngModelPath = extRef.GetAbsolutePath(); string ExistingStringPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(ExsiitngModelPath); string NewStringPath = ExistingStringPath.Replace(@"Testing\A", @"Testing\B"); ModelPath NewPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(NewStringPath); PathType NewPathType = PathType.Relative; transData.SetDesiredReferenceData(refId, NewPath, NewPathType, ShouldLoad); transData.IsTransmitted = true; TransmissionData.WriteTransmissionData(path, transData); trans.Commit(); } } } } else { TaskDialog.Show("Unload Links", "The document does not have any transmission data"); } }