コード例 #1
0
ファイル: Updater.cs プロジェクト: Vitaclick/Revit.Updater
        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);
            }
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
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");
            }
        }
        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);
        }