BuildingCoder.CmdFamilyParamValue.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 app = commandData.Application;
              Document doc = app.ActiveUIDocument.Document;
              if( !doc.IsFamilyDocument )
              {
            message =
              "Please run this command in a family document.";
              }
              else
              {
            FamilyManager mgr = doc.FamilyManager;

            int n = mgr.Parameters.Size;

            Debug.Print(
              "\nFamily {0} has {1} parameter{2}.",
              doc.Title, n, Util.PluralSuffix( n ) );

            Dictionary<string, FamilyParameter> fps
              = new Dictionary<string, FamilyParameter>( n );

            foreach( FamilyParameter fp in mgr.Parameters )
            {
              string name = fp.Definition.Name;
              fps.Add( name, fp );

              #region Look at associated parameters
            #if LOOK_AT_ASSOCIATED_PARAMETERS
              ParameterSet ps = fp.AssociatedParameters;
              n = ps.Size;

              string values = string.Empty;
              foreach( Parameter p in ps )
              {
            if( 0 == values.Length )
            {
              values = " ";
            }
            else
            {
              values += ", ";
            }
            values += p.AsValueString();
              }

              Debug.Print(
            "Parameter {0} has {1} associated parameter{2}{3}{4}.",
            name,
            n,
            PluralSuffix( n ),
            ( 0 < n ? ":" : "" ),
            values );
            #endif // LOOK_AT_ASSOCIATED_PARAMETERS
              #endregion // Look at associated parameters

            }
            List<string> keys = new List<string>( fps.Keys );
            keys.Sort();

            n = mgr.Types.Size;

            Debug.Print(
              "Family {0} has {1} type{2}{3}",
              doc.Title,
              n,
              Util.PluralSuffix( n ),
              Util.DotOrColon( n ) );

            foreach( FamilyType t in mgr.Types )
            {
              string name = t.Name;
              Debug.Print( "  {0}:", name );
              foreach( string key in keys )
              {
            FamilyParameter fp = fps[key];
            if( t.HasValue( fp ) )
            {
              string value
                = FamilyParamValueString( t, fp, doc );

              Debug.Print( "    {0} = {1}", key, value );
            }
              }
            }
              }

              #region Exercise ExtractPartAtomFromFamilyFile

              // by the way, here is a completely different way to
              // get at all the parameter values, and all the other
              // family information as well:

              bool exercise_this_method = false;

              if( doc.IsFamilyDocument && exercise_this_method )
              {
            string path = doc.PathName;
            if( 0 < path.Length )
            {
              app.Application.ExtractPartAtomFromFamilyFile(
            path, path + ".xml" );
            }
              }
              #endregion // Exercise ExtractPartAtomFromFamilyFile

              return Result.Failed;
        }