BuildingCoder.CmdLinkedFiles.Execute C# (CSharp) Method

Execute() public method

public Execute ( ExternalCommandData commandData, string &message, ElementSet elements ) : System.Result
commandData ExternalCommandData
message string
elements ElementSet
return System.Result
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
              Application app = uiapp.Application;
              Document doc = uiapp.ActiveUIDocument.Document;

              Dictionary<string, string> dict
            = GetFilePaths( app, true );

              IList<Element> links
            = GetLinkedFiles( doc ).ToElements();

              int n = links.Count;
              Debug.Print(
            "There {0} {1} linked Revit model{2}.",
            ( 1 == n ? "is" : "are" ), n,
            Util.PluralSuffix( n ) );

              string name;
              char[] sep = new char[] { ':' };
              string[] a;

              foreach( Element link in links )
              {
            name = link.Name;
            a = name.Split( sep );
            name = a[0].Trim();

            Debug.Print(
              "Link '{0}' full path is '{1}'.",
              name, dict[name] );

            #region Explore Location
            Location loc = link.Location; // unknown content in here
            LocationPoint lp = loc as LocationPoint;
            if( null != lp )
            {
              XYZ p = lp.Point;
            }
            GeometryElement e = link.get_Geometry( new Options() );
            if( null != e ) // no geometry defined
            {
              //GeometryObjectArray objects = e.Objects; // 2012
              //n = objects.Size; // 2012
              n = e.Count<GeometryObject>(); // 2013
            }
            #endregion // Explore Location

            #region Explore Pinning
            if( link is ImportInstance ) // nope, this never happens ...
            {
              ImportInstance i = link as ImportInstance;
              string s = i.Pinned ? "" : "not ";
              Debug.Print( "{1}pinned", s );
              i.Pinned = !i.Pinned;
            }
            #endregion // Explore Pinning
              }
              return Result.Succeeded;
        }