BuildingCoder.CmdChangeLinkedFilePath.Execute C# (CSharp) Méthode

Execute() public méthode

public Execute ( ExternalCommandData commandData, string &message, ElementSet elements ) : System.Result
commandData ExternalCommandData
message string
elements ElementSet
Résultat System.Result
        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;
        }
CmdChangeLinkedFilePath