private void CloseModelLinks(ModelPath modelPath) { // Access transmission data in the given file TransmissionData trans = TransmissionData.ReadTransmissionData(modelPath); if (trans != null) { // collect all external references var externalReferences = trans.GetAllExternalFileReferenceIds(); foreach (ElementId extRefId in externalReferences) { var extRef = trans.GetLastSavedReferenceData(extRefId); if (extRef.ExternalFileReferenceType == ExternalFileReferenceType.RevitLink) { // var p = ModelPathUtils.ConvertModelPathToUserVisiblePath(extRef.GetPath()); //set data trans.SetDesiredReferenceData(extRefId, extRef.GetPath(), extRef.PathType, false); Debug.Write($"{extRef.GetPath().CentralServerPath} " + $"{extRef.GetPath().ServerPath}"); } } // make sure the IsTransmitted property is set trans.IsTransmitted = true; // modified transmissoin data must be saved back to the model TransmissionData.WriteTransmissionData(modelPath, trans); } }
// sample code from RevitAPI.chm entry // on the TransmissionData class: /// <summary> /// Unload all Revit links. /// This method will set all Revit links to be /// unloaded the next time the document at the /// given location is opened. /// The TransmissionData for a given document /// only contains top-level Revit links, not /// nested links. /// However, nested links will be unloaded if /// their parent links are unloaded, so this /// function only needs to look at the /// document's immediate links. /// </summary> void UnloadRevitLinks(ModelPath location) { // access transmission data in the given Revit file TransmissionData transData = TransmissionData .ReadTransmissionData(location); 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) { // we do not want to change neither the // path nor the path-type; we only want // the links to be unloaded (shouldLoad // = false) transData.SetDesiredReferenceData(refId, extRef.GetPath(), extRef.PathType, false); } } // make sure the IsTransmitted property is set transData.IsTransmitted = true; // modified transmission data must be saved back to the model TransmissionData.WriteTransmissionData( location, transData); } else { TaskDialog.Show( "Unload Links", "The document does not have any transmission data"); } }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; FilePath location = new FilePath("C:/file.rvt"); TransmissionData transData = TransmissionData.ReadTransmissionData( location); if (null != transData) { // 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) { // Change the path of the linked file, // leaving everything else unchanged: transData.SetDesiredReferenceData(refId, new FilePath("C:/MyNewPath/cut.rvt"), extRef.PathType, true); } } // Make sure the IsTransmitted property is set transData.IsTransmitted = true; // Modified transmission data must be saved // back to the model TransmissionData.WriteTransmissionData( location, transData); } else { TaskDialog.Show("Unload Links", "The document does not have" + " any transmission data"); } return(Result.Succeeded); }