BuildingCoder.CmdSheetSize.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 app = commandData.Application;
              Document doc = app.ActiveUIDocument.Document;

              FilteredElementCollector a;
              Parameter p;
              int n;

              #region Using the obsolete TitleBlocks property
            #if BEFORE_REVIT_2015
              // The TitleBlocks property was declared deprecated
              // in the Revit 2014 API, and removed in Revit 2015.

              // Using the obsolete deprecated TitleBlocks property

              FamilySymbolSet titleBlocks = doc.TitleBlocks;

              n = titleBlocks.Size;

              Debug.Print(
            "{0} title block element type{1} listed "
            + "in doc.TitleBlocks collection{2}",
            n,
            ( 1 == n ? "" : "s" ),
            ( 0 == n ? "." : ":" ) );

              string s;

              foreach( FamilySymbol tb in titleBlocks )
              {
            // these are the family symbols,
            // i.e. the title block element types,
            // i.e. not instances, i.e. not sheets,
            // and they obviously do not have any sheet
            // number, width or height, so 's' ends up empty:

            s = GetParameterValueString( tb, BuiltInParameter.SHEET_NUMBER )
              + GetParameterValueString( tb, BuiltInParameter.SHEET_WIDTH )
              + GetParameterValueString( tb, BuiltInParameter.SHEET_HEIGHT );

            Debug.Print(
              "Title block element type {0} {1}" + s,
              tb.Name, tb.Id.IntegerValue );
              }
            #endif // BEFORE_REVIT_2015
              #endregion // Using the obsolete TitleBlocks property

              // Using this filter returns the same elements
              // as the doc.TitleBlocks collection:

              a = new FilteredElementCollector( doc )
            .OfCategory( BuiltInCategory.OST_TitleBlocks )
            .OfClass( typeof( FamilySymbol ) );

              n = a.ToElementIds().Count;

              Debug.Print( "{0} title block element type{1} "
            + "retrieved by filtered element collector{2}",
            n,
            ( 1 == n ? "" : "s" ),
            ( 0 == n ? "." : ":" ) );

              foreach( FamilySymbol symbol in a )
              {
            Debug.Print(
              "Title block element type {0} {1}",
              symbol.Name, symbol.Id.IntegerValue );
              }

              // Retrieve the title block instances:

              a = new FilteredElementCollector( doc )
            .OfCategory( BuiltInCategory.OST_TitleBlocks )
            .OfClass( typeof( FamilyInstance ) );

              Debug.Print( "Title block instances:" );

              foreach( FamilyInstance e in a )
              {
            p = e.get_Parameter(
              BuiltInParameter.SHEET_NUMBER );

            Debug.Assert( null != p,
              "expected valid sheet number" );

            string sheet_number = p.AsString();

            p = e.get_Parameter(
              BuiltInParameter.SHEET_WIDTH );

            Debug.Assert( null != p,
              "expected valid sheet width" );

            string swidth = p.AsValueString();
            double width = p.AsDouble();

            p = e.get_Parameter(
              BuiltInParameter.SHEET_HEIGHT );

            Debug.Assert( null != p,
              "expected valid sheet height" );

            string sheight = p.AsValueString();
            double height = p.AsDouble();

            ElementId typeId = e.GetTypeId();
            Element type = doc.GetElement( typeId );

            Debug.Print(
              "Sheet number {0} size is {1} x {2} "
              + "({3} x {4}), id {5}, type {6} {7}",
              sheet_number, swidth, sheight,
              Util.RealString( width ),
              Util.RealString( height ),
              e.Id.IntegerValue,
              type.Name, typeId.IntegerValue );
              }

              // Retrieve the view sheet instances:

              a = new FilteredElementCollector( doc )
            .OfClass( typeof( ViewSheet ) );

              Debug.Print( "View sheet instances:" );

              foreach( ViewSheet vs in a )
              {
            string number = vs.SheetNumber;
            Debug.Print(
              "View sheet name {0} number {1} id {2}",
              vs.Name, vs.SheetNumber,
              vs.Id.IntegerValue );
              }
              return Result.Succeeded;
        }