BuildingCoder.CmdRemoveImportedJpgs.Execute C# (CSharp) Метод

Execute() публичный Метод

public Execute ( ExternalCommandData commandData, string &message, ElementSet elements ) : System.Result
commandData ExternalCommandData
message string
elements ElementSet
Результат System.Result
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
              UIDocument uidoc = uiapp.ActiveUIDocument;
              Document doc = uidoc.Document;

              FilteredElementCollector col
            = new FilteredElementCollector( doc )
              .WhereElementIsNotElementType();

              List<ElementId> ids = new List<ElementId>();

              foreach( Element e in col )
              {
            if( ElementNameMayIndicateImageFileReference( e ) )
            {
              Debug.Print( Util.ElementDescription( e ) );
              ids.Add( e.Id );
            }
              }

              ICollection<ElementId> idsDeleted = null;
              Transaction t;

              int n = ids.Count;

              if( 0 < n )
              {
            using( t = new Transaction( doc ) )
            {
              t.Start( "Delete non-ElementType '.jpg' elements" );

              idsDeleted = doc.Delete( ids );

              t.Commit();
            }
              }

              int m = ( null == idsDeleted )
            ? 0
            : idsDeleted.Count;

              Debug.Print( string.Format(
            "Selected {0} non-ElementType element{1}, "
            + "{2} successfully deleted.",
            n, Util.PluralSuffix( n ), m ) );

              col = new FilteredElementCollector( doc )
            .WhereElementIsElementType();

              ids.Clear();

              foreach( Element e in col )
              {
            if( ElementNameMayIndicateImageFileReference( e ) )
            {
              Debug.Print( Util.ElementDescription( e ) );
              ids.Add( e.Id );
            }
              }

              n = ids.Count;

              if( 0 < n )
              {
            using( t = new Transaction( doc ) )
            {
              t.Start( "Delete element type '.jpg' elements" );

              idsDeleted = doc.Delete( ids );

              t.Commit();
            }
              }

              m = ( null == idsDeleted ) ? 0 : idsDeleted.Count;

              Debug.Print( string.Format(
            "Selected {0} element type{1}, "
            + "{2} successfully deleted.",
            n, Util.PluralSuffix( n ), m ) );

              return Result.Succeeded;
        }