void GetKeynotesAssemblyCodesSharedParamAndLinks(IList <Document> targetDocumentsList, IList <string> targetList, Document activeDoc) { foreach (Document currentDoc in targetDocumentsList) { ModelPath targetLocation = ModelPathUtils.ConvertUserVisiblePathToModelPath(currentDoc.PathName); TransmissionData targetData = TransmissionData.ReadTransmissionData(targetLocation); if (targetData != null) { ICollection <ElementId> externalReferences = targetData.GetAllExternalFileReferenceIds(); foreach (ElementId currentFileId in externalReferences) { if (currentFileId != ElementId.InvalidElementId) { ExternalFileReference extRef = targetData.GetLastSavedReferenceData(currentFileId); //TODO CORRECT PROBLEMATIC IF STATEMENT HERE!!!!!!!!!!!!!!!!!! if (extRef.GetLinkedFileStatus() != LinkedFileStatus.Invalid) { ModelPath currenFileLink = extRef.GetAbsolutePath(); if (!currenFileLink.Empty) { string currentFileLinkString = ModelPathUtils.ConvertModelPathToUserVisiblePath(currenFileLink); CheckStringAValidLinkPathCorrectItAndAddToList(currentFileLinkString, targetList, activeDoc); } } } } } } }
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); } }
// bug683 fix: functie toegevoegd zodat IFC exporter selectief kan rapporteren welke files missen /// <summary> /// Geef alle gelinkte files die niet langer gevonden kunnen worden /// </summary> /// <param name="app"></param> /// <param name="addProj"></param> /// <returns></returns> // ReSharper disable once UnusedMember.Global public static List <string> GetMissingLinkedFiles(UIApplication app, bool addProj) { List <string> linkedProjects = new List <string>(); if (linkedProjects.Count == 0) { // er zijn waarschijnlijk worksets gebruikt ModelPath mdlPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(app.ActiveUIDocument.Document.PathName); TransmissionData transData = TransmissionData.ReadTransmissionData(mdlPath); if (transData != null) { ICollection <ElementId> externalReferences = transData.GetAllExternalFileReferenceIds(); foreach (ElementId refId in externalReferences) { ExternalFileReference curRef = transData.GetLastSavedReferenceData(refId); string refType = curRef.ExternalFileReferenceType.ToString(); string refPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(curRef.GetAbsolutePath()); if (refType == "RevitLink") { linkedProjects.Add(refPath); } } } } if (addProj) { linkedProjects.Add(app.ActiveUIDocument.Document.PathName); } //laatste check om te kijken of de links ook gevonden worden return(linkedProjects.Where(p => (false == File.Exists(p))).ToList()); }
/// <summary> /// Sets the revit link list. /// </summary> /// <param name="centralPath"></param> /// <param name="linkPaths"></param> public static void SetRevitLinkList(string centralPath, List <string> linkPaths) { if (centralPath is null) { throw new ArgumentNullException(nameof(centralPath)); } if (linkPaths is null) { throw new ArgumentNullException(nameof(linkPaths)); } var transData = TransmissionData.ReadTransmissionData(new FilePath(centralPath)); if (transData is null) { return; } // If found not the link, don't submit, otherwise throw file writing exception. var flag = false; foreach (var referId in transData.GetAllExternalFileReferenceIds()) { var extRef = transData.GetLastSavedReferenceData(referId); if (extRef.ExternalFileReferenceType != ExternalFileReferenceType.RevitLink) { continue; } var userPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(extRef.GetPath()); var linkPath = linkPaths.FirstOrDefault(w => w != null && userPath.Contains(Path.GetFileName(w))); if (linkPath is null) { continue; } var elmId = extRef.GetReferencingId(); transData.SetDesiredReferenceData(elmId, new FilePath(linkPath), PathType.Relative, true); flag = true; } if (!flag) { return; } transData.IsTransmitted = true; TransmissionData.WriteTransmissionData(new FilePath(centralPath), transData); }
// 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"); } }
/// <inheritdoc/> internal override int Execute(string args = null) { var filepath = _doc.PathName; if (filepath != null) { IList <Element> xRefLinks = new List <Element>(); var modelPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(filepath); var wasException = false; try { var transData = TransmissionData.ReadTransmissionData(modelPath); var externalReferences = transData.GetAllExternalFileReferenceIds(); foreach (var xRefId in externalReferences) { var externalReference = _doc.GetElement(xRefId); if (ConfirmRemoval(externalReference)) { xRefLinks.Add(externalReference); } } HelperMethods.RemoveElements(Name, _doc, xRefLinks); } catch { wasException = true; } try { var linkTypesIds = new FilteredElementCollector(_doc).OfClass(typeof(RevitLinkType)).Select(l => l.Id).ToList(); HelperMethods.RemoveElements(Name, _doc, linkTypesIds); } catch { wasException = true; } return(wasException ? 0 : 1); } // Модель должна быть сохранена для удаления внешних ссылок MessageBox.Show(Language.GetItem(RevitCommand.LangItem, "m1"), MessageBoxIcon.Alert); return(0); }
/// <summary> /// Geef alle gelinkte files /// </summary> /// <param name="app"></param> /// <param name="addProj"></param> /// <returns></returns> public static List <string> GetLinkedFiles(UIApplication app, bool addProj) { List <string> linkedProjects = new List <string>(); List <RevitLinkInstance> instantiekes = GetAllProjectElements(app.ActiveUIDocument.Document) .OfType <RevitLinkInstance>() .Where(c => c.Name.ToLower().Contains(".rvt")) .ToList(); foreach (RevitLinkInstance rli in instantiekes) { if (rli.GetLinkDocument() == null) { continue; } string linknaam = rli.GetLinkDocument().PathName; if (!linkedProjects.Contains(linknaam)) { linkedProjects.Add(linknaam); } } if (linkedProjects.Count == 0) { // er zijn waarschijnlijk worksets gebruikt ModelPath mdlPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(app.ActiveUIDocument.Document.PathName); TransmissionData transData = TransmissionData.ReadTransmissionData(mdlPath); if (transData != null) { ICollection <ElementId> externalReferences = transData.GetAllExternalFileReferenceIds(); foreach (ElementId refId in externalReferences) { ExternalFileReference curRef = transData.GetLastSavedReferenceData(refId); string refType = curRef.ExternalFileReferenceType.ToString(); string refPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(curRef.GetAbsolutePath()); if (refType == "RevitLink") { linkedProjects.Add(refPath); } } } } if (addProj) { linkedProjects.Add(app.ActiveUIDocument.Document.PathName); } //laatste check om te kijken of de links ook gevonden worden return(linkedProjects.Where(File.Exists).ToList()); }
private void app_ListOfLinks(ModelPath modelPath) { var temp = new List <ModelPath>(); var trans = new TransmissionData(TransmissionData.ReadTransmissionData(modelPath)); foreach (var refId in trans.GetAllExternalFileReferenceIds()) { var extRef = trans.GetLastSavedReferenceData(refId); if (extRef.ExternalFileReferenceType == ExternalFileReferenceType.RevitLink) { var path = extRef.GetPath(); temp.Add(path); } } Globals.data.Add(temp); }
private static List <RevitLink> GetLinks(string location) { List <RevitLink> links = new List <RevitLink>(); try { ModelPath path = ModelPathUtils.ConvertUserVisiblePathToModelPath(location); TransmissionData transData = TransmissionData.ReadTransmissionData(path); ICollection <ElementId> externalReferences = default(ICollection <ElementId>); if (transData != null) { // collect all (immediate) external references in the model externalReferences = transData.GetAllExternalFileReferenceIds(); if (externalReferences.Count > 0) { foreach (ElementId refId in externalReferences) { ExternalFileReference extRef = transData.GetLastSavedReferenceData(refId); if (extRef.IsValidObject) { if (extRef.ExternalFileReferenceType == ExternalFileReferenceType.CADLink | extRef.ExternalFileReferenceType == ExternalFileReferenceType.DWFMarkup | extRef.ExternalFileReferenceType == ExternalFileReferenceType.RevitLink) { RevitLink rl = new RevitLink(); rl.LinkType = extRef.ExternalFileReferenceType.ToString(); rl.AbsolutePath = ModelPathUtils.ConvertModelPathToUserVisiblePath(extRef.GetAbsolutePath()); rl.Path = ModelPathUtils.ConvertModelPathToUserVisiblePath(extRef.GetPath()); links.Add(rl); } } } } } } catch (Exception) { } return(links); }
/// <summary> /// Get paths of external references associated with the Revit document used to initialize the class. /// </summary> /// <returns>A dictionary of reference types, and reference paths.</returns> public Dictionary <ExternalFileReferenceType, string> GetExternalReferencePaths() { Dictionary <ExternalFileReferenceType, string> referenceDictionary = new Dictionary <ExternalFileReferenceType, string>(); string location = Doc.PathName; try { ModelPath modelPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(location); TransmissionData transData = TransmissionData.ReadTransmissionData(modelPath); ICollection <ElementId> externalFileReferenceIds = transData.GetAllExternalFileReferenceIds(); foreach (ElementId referenceElementId in externalFileReferenceIds) { ExternalFileReference externalFileReference = transData.GetLastSavedReferenceData(referenceElementId); ModelPath refPath = externalFileReference.GetPath(); string path = ModelPathUtils.ConvertModelPathToUserVisiblePath(refPath); ExternalFileReferenceType referenceType = externalFileReference.ExternalFileReferenceType; referenceDictionary.Add(referenceType, path); } } catch (Exception exceptionReference) { Console.WriteLine(exceptionReference.ToString()); } return(referenceDictionary); }
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); }
/// <summary> /// List all DWG, RVT and other links of a given document. /// </summary> void ListLinks(ModelPath location) { string path = ModelPathUtils .ConvertModelPathToUserVisiblePath(location); string content = string.Format( "The document at '{0}' ", path); List <string> links = null; // access transmission data in the given Revit file TransmissionData transData = TransmissionData .ReadTransmissionData(location); if (transData == null) { content += "does not have any transmission data"; } else { // collect all (immediate) external references in the model ICollection <ElementId> externalReferences = transData.GetAllExternalFileReferenceIds(); int n = externalReferences.Count; content += string.Format( "has {0} external reference{1}{2}", n, PluralSuffix(n), DotOrColon(n)); links = new List <string>(n); // find every reference that is a link foreach (ElementId refId in externalReferences) { ExternalFileReference extRef = transData.GetLastSavedReferenceData(refId); links.Add(string.Format("{0} {1}", extRef.ExternalFileReferenceType, ModelPathUtils.ConvertModelPathToUserVisiblePath( extRef.GetPath()))); } } Debug.Print(content); TaskDialog dlg = new TaskDialog("List Links"); dlg.MainInstruction = content; if (null != links && 0 < links.Count) { string s = string.Join(" \r\n", links.ToArray()); Debug.Print(s); dlg.MainContent = s; } dlg.Show(); }