Esempio n. 1
0
        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);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        // 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());
        }
Esempio n. 4
0
        // 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");
            }
        }
Esempio n. 5
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());
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        /// <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);
        }
Esempio n. 10
0
        /// <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();
        }