// 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()); }
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); } } } } } } }
// 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"); } }
/// <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 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); }
public static void updateLinks(UIApplication uiapp) { Document doc = uiapp.ActiveUIDocument.Document; FilteredElementCollector links = new FilteredElementCollector(doc) .OfCategory(BuiltInCategory.OST_RvtLinks); foreach (Element e in links) { if (e is RevitLinkInstance) { RevitLinkInstance ee = e as RevitLinkInstance; ExternalFileReference er = e.GetExternalFileReference(); if (er != null) { ModelPath mp = er.GetPath(); string userVisiblePath = ModelPathUtils.ConvertModelPathToUserVisiblePath(mp); //if(ee.Is) } } } }
public string FindDiffuseTextureDecal(Element element) { //查找漫反射纹理贴图 try { // 获取元素ID ElementId typeId = element.GetTypeId(); //获取外部文件参考 ExternalFileReference externalFileReference = (document.GetElement(typeId) as ElementType).GetExternalFileReference(); //判断外部文件参考类型是不是 if (externalFileReference.ExternalFileReferenceType.Equals(AssetPropertyType.Float)) { //是的话将模型路径转换为用户可见路径,(链接模型的完整路径作为参数) string inputPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(externalFileReference.GetAbsolutePath()); //最后返回文件绝对路径。 return(FixTexturePath(inputPath)); } } catch (Exception) { } return(""); }
/// <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); }
/// <summary> /// Remove DWF links from model and return /// the total number of deleted elements. /// </summary> int RemoveDwfLinkUsingExternalFileUtils( Document doc) { List <ElementId> idsToDelete = new List <ElementId>(); ICollection <ElementId> ids = ExternalFileUtils .GetAllExternalFileReferences(doc); foreach (ElementId id in ids) { Element e = doc.GetElement(id); Debug.Print(Util.ElementDescription(e)); ExternalFileReference xr = ExternalFileUtils .GetExternalFileReference(doc, id); ExternalFileReferenceType xrType = xr.ExternalFileReferenceType; if (xrType == ExternalFileReferenceType.DWFMarkup) { ModelPath xrPath = xr.GetPath(); string path = ModelPathUtils .ConvertModelPathToUserVisiblePath(xrPath); if (path.EndsWith(".dwf") || path.EndsWith(".dwfx")) { idsToDelete.Add(id); } } } int n = idsToDelete.Count; ICollection <ElementId> idsDeleted = null; if (0 < n) { using (Transaction t = new Transaction(doc)) { t.Start("Delete DWFx Links"); idsDeleted = doc.Delete(idsToDelete); t.Commit(); } } int m = (null == idsDeleted) ? 0 : idsDeleted.Count; Debug.Print(string.Format( "Selected {0} DWF external file reference{1}, " + "{2} element{3} successfully deleted.", n, Util.PluralSuffix(n), m, Util.PluralSuffix(m))); return(m); }
void MiroReloadLinks(IList <RevitLinkType> fecLinkTypes) { // Loop all RVT Links foreach (RevitLinkType typeLink in fecLinkTypes) { // ... // Skip1 - not IsFromRevitServer if (!typeLink.IsFromRevitServer()) { //… continue; } // Skip2 - not ExternalFileReference // 99% it would already skip above as // RevitServer MUST be ExternalFileReference, // but leave just in case... ExternalFileReference er = typeLink.GetExternalFileReference(); if (er == null) { // ... continue; } // If here, we can cache ModelPath related // info and show to user regardless if we skip // on next checks or not.... ModelPath mp = er.GetPath(); string userVisiblePath = ModelPathUtils .ConvertModelPathToUserVisiblePath(mp); // Skip3 - if ModelPath is NOT Server Path // 99% redundant as we already checked raw // RevitLinkType for this, but keep // just in case... if (!mp.ServerPath) { // ... continue; } // Skip4 - if NOT "NOT Found" problematic one // there is nothing to fix if (er.GetLinkedFileStatus() != LinkedFileStatus.NotFound) { // ... continue; } // Skip5 - if Nested Link (can’t (re)load these!) if (typeLink.IsNestedLink) { // ... continue; } // If here, we MUST offer user to "Reload from..." // ... RevitLinkLoadResult res = null; try { // This fails for problematic Server files // since it also fails on "Reload" button in // UI (due to the GUID issue in the answer) //res = typeLink.Reload(); // This fails same as above :-(! //res = typeLink.Load(); // This WORKS! // Basically, this is the equivalent of UI // "Reload from..." + browsing to the *same* // Saved path showing in the manage Links // dialogue. // ToDo: Check if we need to do anything // special with WorksetConfiguration? // In tests, it works fine with the // default c-tor. ModelPath mpForReload = ModelPathUtils .ConvertUserVisiblePathToModelPath( userVisiblePath); res = typeLink.LoadFrom(mpForReload, new WorksetConfiguration()); Util.InfoMsg(string.Format( "Result = {0}", res.LoadResult)); } catch (Exception ex) { Debug.Print(ex.Message); } } // foreach typeLink }
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(); }