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"); } }
Dear John,
Thank you for your query.
I am pretty sure that you do not need to open or commit any transactions for this operation, since the TransmissionData is not a Revit database element. The call to WriteTransmissionData takes care of saving the data back to the external file.
I think the TransmissionData is part of the external file.
From you question, you seem to want to update the link to it saved in the currenly open Revit project.
For that, you should probably be looking at the RevitLinkInstance class instead, which represents an instance of a RevitLinkType, i.e., a linked file within the project.
Here is an old post of its path property:
The ExternalFileReference.GetPath method read and returns the path of the link, relative or absolute according to the link's settings
That all seems to be read-only, though.
Somebody seems to have tried to achieve the same as you in the past:
The suggestions there lead back to the transmission data approach.
Have you tried modifying the transmission data information without having the project loaded?
Maybe the changes that you set up will only be noticeable if the file is not loaded, and you can see the effect next time you load it.
I hope this helps.
Please let us know how you get on with this and what solution you end up with.
Thank you!
Best regards,
Jeremy
Can't find what you're looking for? Ask the community or share your knowledge.