应用程序:AreaReinParameters

Revit平台:Structure

Revit版本:2011.0

首次发布用于:9.0

编程语言:C#

技能等级:中等

类别:结构

类型:外部命令

主题:区域钢筋和钢筋的参数。

摘要:此示例显示如何使用API显示和修改Area钢筋的参数。并教用户如何获取钢筋的所有参数。

相关类:

Autodesk.Revit.UI.IExternalCommand

Autodesk.Revit.DB.ElementSet

Autodesk.Revit.DB.ElementIterator

Autodesk.Revit.DB.Structure.RebarBarType

Autodesk.Revit.DB.Structure.AreaReinforcementCurve

Autodesk.Revit.DB.BuiltInParameter

项目文件:

AreaReinParameters.cs实现IExternalCommand接口,Class“Command”向用户展示如何获取AreaReinforcement并更改其参数。类“RebarParas”向用户展示如何获取Rebar的所有参数。

FloorAreaReinData.cs  PropertyGrid的数据源。

WallAreaReinData.cs   PropertyGrid的数据源。

ParameterUtil.cs  此文件定义一个类ParameterUtil包含用于管理参数的方法。例如通过名称查找参数和更改参数的值。

功能:

此示例显示如何使用API显示和修改Area钢筋的参数:

更改“构造”组中的布局规则

更改顶部/底部次要/主要条形图类型

更改顶部/底部副钩/主钩方向

更改顶部/底部次要/主要吊钩类型

实施:

1.绘制一个区域钢筋(或打开AreaReinParameters.rvt)并选择它。

2.运行“AreaReinParameters”命令。(菜单->工具->外部工具)3.绘制钢筋(或打开Rebar.rvt)并选择它。

4.运行“RebarParameters”命令。

完整的源代码请加入QQ群649037449,在群文件中下载RevitSDK.exe,解压后在文件夹中搜索本文中应用程序名称即可获得完整源码

AreaReinParameters.cs

//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//


namespace Revit.SDK.Samples.AreaReinParameters.CS
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Collections;
    using System.Windows.Forms;

    using Autodesk.Revit;
    using Autodesk.Revit.DB;
    using Autodesk.Revit.UI;
    using Autodesk.Revit.DB.Structure;

    /// <summary>
    /// Entry point and main command class
    /// </summary>
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
    [Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
    class Command : IExternalCommand
    {
        static ExternalCommandData m_commandData;
        static Hashtable m_hookTypes;
        static Hashtable m_barTypes;
        AreaReinforcement m_areaRein;

        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application 
        /// which contains data related to the command, 
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application 
        /// which will be displayed if a failure or cancellation is returned by 
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application 
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command. 
        /// A result of Succeeded means that the API external method functioned as expected. 
        /// Cancelled can be used to signify that the user cancelled the external operation 
        /// at some point. Failure should be returned if the application is unable to proceed with 
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(
          ExternalCommandData revit,
          ref string message,
          ElementSet elements)
        {
            Transaction trans = new Transaction(revit.Application.ActiveUIDocument.Document, "Revit.SDK.Samples.AreaReinParameters");
            trans.Start();
            m_commandData = revit;
            if (!PreData())
            {
                message = "Please select only one AreaReinforcement and ";
                message += "make sure there are Hook Types and Bar Types in current project.";
                trans.RollBack();
                return Autodesk.Revit.UI.Result.Failed;
            }

            IAreaReinData data = new WallAreaReinData();
            if (!data.FillInData(m_areaRein))
            {
                data = new FloorAreaReinData();
                if (!data.FillInData(m_areaRein))
                {
                    message = "Failed to get properties of selected AreaReinforcement.";
                    trans.RollBack();
                    return Autodesk.Revit.UI.Result.Failed;
                }
            }

            AreaReinParametersForm form = new AreaReinParametersForm(data);
            if (form.ShowDialog() == DialogResult.Cancel)
            {
                trans.RollBack();
                return Autodesk.Revit.UI.Result.Cancelled;
            }
            trans.Commit();
            return Autodesk.Revit.UI.Result.Succeeded;
        }

        /// <summary>
        /// it is convenient for other class to get
        /// </summary>
        public static ExternalCommandData CommandData
        {
            get
            {
                return m_commandData;
            }
        }

        /// <summary>
        /// all hook types in current project
        /// it is static because of IConverter limitation
        /// </summary>
        public static Hashtable HookTypes
        {
            get
            {
                return m_hookTypes;
            }
        }

        /// <summary>
        /// all hook types in current project
        /// it is static because of IConverter limitation
        /// </summary>
        public static Hashtable BarTypes
        {
            get
            {
                return m_barTypes;
            }
        }

        /// <summary>
        /// check whether the selected is expected, find all hooktypes in current project
        /// </summary>
        /// <param name="selected">selected elements</param>
        /// <returns>whether the selected AreaReinforcement is expected</returns>
        private bool PreData()
        {
           ElementSet selected = new ElementSet();
            foreach (ElementId elementId in m_commandData.Application.ActiveUIDocument.Selection.GetElementIds())
            {
               selected.Insert(m_commandData.Application.ActiveUIDocument.Document.GetElement(elementId));
            }

            //selected is not only one AreaReinforcement
            if (selected.Size != 1)
            {
                return false;
            }
            foreach (Object o in selected)
            {
                m_areaRein = o as AreaReinforcement;
            }
            if (null == m_areaRein)
            {
                return false;
            }

            //make sure hook type and bar type exist in current project and get them
            m_hookTypes = new Hashtable();
            m_barTypes = new Hashtable();

            Document activeDoc = m_commandData.Application.ActiveUIDocument.Document;


            FilteredElementIterator itor = (new FilteredElementCollector(activeDoc)).OfClass(typeof(RebarHookType)).GetElementIterator();
            itor.Reset();
            while (itor.MoveNext())
            {
                RebarHookType hookType = itor.Current as RebarHookType;
                if (null != hookType)
                {
                    string hookTypeName = hookType.Name;
                    m_hookTypes.Add(hookTypeName, hookType.Id);
                }
            }

            itor = (new FilteredElementCollector(activeDoc)).OfClass(typeof(RebarBarType)).GetElementIterator();
            itor.Reset();
            while (itor.MoveNext())
            {
                RebarBarType barType = itor.Current as RebarBarType;
                if (null != barType)
                {
                    string barTypeName = barType.Name;
                    m_barTypes.Add(barTypeName, barType.Id);
                }
            }
            if (m_hookTypes.Count == 0 || m_barTypes.Count == 0)
            {
                return false;
            }

            return true;
        }
    }

    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
    class RebarParas : IExternalCommand
    {
        public Autodesk.Revit.UI.Result Execute(
          ExternalCommandData revit,
          ref string message,
          ElementSet elements)
        {
            try
            {
                // Get the active document and view
                UIDocument revitDoc = revit.Application.ActiveUIDocument;
                Autodesk.Revit.DB.View view = revitDoc.Document.ActiveView;
                foreach (Autodesk.Revit.DB.ElementId elemId in revitDoc.Selection.GetElementIds())
                {
                    //if( elem.GetType() == typeof( Autodesk.Revit.DB.Structure.Rebar ) )
                   Autodesk.Revit.DB.Element elem = revitDoc.Document.GetElement(elemId);
                    if (elem is Rebar)
                    {
                        string str = "";
                        Autodesk.Revit.DB.Structure.Rebar rebar = (Autodesk.Revit.DB.Structure.Rebar)elem;
                        ParameterSet pars = rebar.Parameters;
                        foreach (Parameter param in pars)
                        {
                            string val = "";
                            string name = param.Definition.Name;
                            Autodesk.Revit.DB.StorageType type = param.StorageType;
                            switch (type)
                            {
                                case Autodesk.Revit.DB.StorageType.Double:
                                    val = param.AsDouble().ToString();
                                    break;
                                case Autodesk.Revit.DB.StorageType.ElementId:
                                    Autodesk.Revit.DB.ElementId id = param.AsElementId();
                                    Autodesk.Revit.DB.Element paraElem = revitDoc.Document.GetElement(id);
                                    if (paraElem != null)
                                        val = paraElem.Name;
                                    break;
                                case Autodesk.Revit.DB.StorageType.Integer:
                                    val = param.AsInteger().ToString();
                                    break;
                                case Autodesk.Revit.DB.StorageType.String:
                                    val = param.AsString();
                                    break;
                                default:
                                    break;
                            }
                            str = str + name + ": " + val + "\r\n";
                        }
                        TaskDialog.Show("Rebar parameters", str);
                        return Autodesk.Revit.UI.Result.Succeeded;
                    }
                }
                message = "No rebar selected!";
                return Autodesk.Revit.UI.Result.Failed;
            }
            catch (Exception e)
            {
                message = e.Message;
                return Autodesk.Revit.UI.Result.Failed;
            }
        }
    }
}

FloorAreaReinData.cs

//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//


namespace Revit.SDK.Samples.AreaReinParameters.CS
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;
    using System.ComponentModel;

    using Autodesk.Revit;
    using Autodesk.Revit.DB;
    using Autodesk.Revit.DB.Structure;


    /// <summary>
    /// can be the datasource of propertygrid
    /// </summary>
    class FloorAreaReinData : IAreaReinData
    {
        //member
        Parameter m_layoutRule;
        //top major layer
        Parameter m_topMajorBarType = null;
        Parameter m_topMajorHookType = null;
        Parameter m_topMajorHookOrientation = null;

        //top minor layer
        Parameter m_topMinorBarType = null;
        Parameter m_topMinorHookType = null;
        Parameter m_topMinorHookOrientation = null;

        //bottom major layer
        Parameter m_bottomMajorBarType = null;
        Parameter m_bottomMajorHookType = null;
        Parameter m_bottomMajorHookOrientation = null;

        //bottom minor layer
        Parameter m_bottomMinorBarType = null;
        Parameter m_bottomMinorHookType = null;
        Parameter m_bottomMinorHookOrientation = null;

        /// <summary>
        /// fill in data with given AreaReinforcement
        /// </summary>
        /// <param name="areaRein"></param>
        /// <returns></returns>
        public bool FillInData(AreaReinforcement areaRein)
        {
            bool flag = false;

            //member
            m_layoutRule = areaRein.get_Parameter(
                BuiltInParameter.REBAR_SYSTEM_LAYOUT_RULE);
            flag = (m_layoutRule != null);

            //top major layer
            m_topMajorBarType = areaRein.get_Parameter(
                BuiltInParameter.REBAR_SYSTEM_BAR_TYPE_TOP_DIR_1);
            m_topMajorHookType = areaRein.get_Parameter(
                BuiltInParameter.REBAR_SYSTEM_HOOK_TYPE_TOP_DIR_1);
            m_topMajorHookOrientation = areaRein.get_Parameter(
                BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_TOP_DIR_1);
            flag &= (m_topMajorBarType != null) && (m_topMajorHookOrientation != null)
                && (m_topMajorHookType != null);

            //top minor layer
            m_topMinorBarType = areaRein.get_Parameter(
                BuiltInParameter.REBAR_SYSTEM_BAR_TYPE_TOP_DIR_2);
            m_topMinorHookType = areaRein.get_Parameter(
                BuiltInParameter.REBAR_SYSTEM_HOOK_TYPE_TOP_DIR_2);
            m_topMinorHookOrientation = areaRein.get_Parameter(
                BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_TOP_DIR_2);
            flag &= (m_topMinorBarType != null) && (m_topMinorHookOrientation != null) 
                && (m_topMinorHookType != null);

            //bottom major layer
            m_bottomMajorBarType = areaRein.get_Parameter(
                BuiltInParameter.REBAR_SYSTEM_BAR_TYPE_BOTTOM_DIR_1);
            m_bottomMajorHookType = areaRein.get_Parameter(
                BuiltInParameter.REBAR_SYSTEM_HOOK_TYPE_BOTTOM_DIR_1);
            m_bottomMajorHookOrientation = areaRein.get_Parameter(
                BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_BOTTOM_DIR_1);
            flag &= (m_bottomMajorBarType != null) && (m_bottomMajorHookOrientation != null)
                && (m_bottomMajorHookType != null);

            //bottom minor layer
            m_bottomMinorBarType = areaRein.get_Parameter(
                BuiltInParameter.REBAR_SYSTEM_BAR_TYPE_BOTTOM_DIR_2);
            m_bottomMinorHookType = areaRein.get_Parameter(
                BuiltInParameter.REBAR_SYSTEM_HOOK_TYPE_BOTTOM_DIR_2);
            m_bottomMinorHookOrientation = areaRein.get_Parameter(
                BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_BOTTOM_DIR_2);
            flag &= (m_bottomMinorBarType != null) && (m_bottomMinorHookOrientation != null) 
                && (m_bottomMinorHookType != null);

            return flag;
        }

        /// <summary>
        /// layout rule
        /// </summary>
        [Category("Construction")]
        public LayoutRules Layout_Rule
        {
            get
            {
                int index = m_layoutRule.AsInteger();
                return (LayoutRules)index;
            }
            set
            {
                int index = (int)value;
                m_layoutRule.Set(index);
            }
        }

        #region top major layer
        [CategoryAttribute("Top Major Layer"), TypeConverter(typeof(BarTypeItem))]
        public Autodesk.Revit.DB.ElementId Top_Major_Bar_Type
        {
            get
            { 
                return m_topMajorBarType.AsElementId();
            }
            set
            {
                m_topMajorBarType.Set(value); 
            }
        }

        [CategoryAttribute("Top Major Layer"), TypeConverter(typeof(HookTypeItem))]
        public Autodesk.Revit.DB.ElementId Top_Major_Hook_Type
        {
            get
            { 
                return m_topMajorHookType.AsElementId();
            }
            set
            { 
                m_topMajorHookType.Set(value);
            }
        }

        [CategoryAttribute("Top Major Layer")]
        public FloorHookOrientations Top_Major_Hook_Orientation
        {
            get
            {
                int index = m_topMajorHookOrientation.AsInteger();
                return (FloorHookOrientations)index;
            }
            set 
            {
                int index = (int)value;
                m_topMajorHookOrientation.Set(index);
            }
        }
        #endregion

        #region top minor layer
        [CategoryAttribute("Top Minor Layer"), TypeConverter(typeof(BarTypeItem))]
        public Autodesk.Revit.DB.ElementId Top_Minor_Bar_Type
        {
            get
            {
                return m_topMinorBarType.AsElementId();
            }
            set
            {
                m_topMinorBarType.Set(value);
            }
        }

        [CategoryAttribute("Top Minor Layer"), TypeConverter(typeof(HookTypeItem))]
        public Autodesk.Revit.DB.ElementId Top_Minor_Hook_Type
        {
            get
            {
                return m_topMinorHookType.AsElementId();
            }
            set
            {
                m_topMinorHookType.Set(value);
            }
        }

        [CategoryAttribute("Top Minor Layer")]
        public FloorHookOrientations Top_Minor_Hook_Orientation
        {
            get
            {
                int index = m_topMinorHookOrientation.AsInteger();
                return (FloorHookOrientations)index;
            }
            set
            {
                int index = (int)value;
                m_topMinorHookOrientation.Set(index);
            }
        }
        #endregion

        #region bottom major layer
        [CategoryAttribute("Bottom Major Layer"), TypeConverter(typeof(BarTypeItem))]
        public Autodesk.Revit.DB.ElementId Bottom_Major_Bar_Type
        {
            get
            {
                return m_bottomMajorBarType.AsElementId();
            }
            set
            {
                m_bottomMajorBarType.Set(value);
            }
        }

        [CategoryAttribute("Bottom Major Layer"), TypeConverter(typeof(HookTypeItem))]
        public Autodesk.Revit.DB.ElementId Bottom_Major_Hook_Type
        {
            get
            {
                return m_bottomMajorHookType.AsElementId();
            }
            set
            {
                m_bottomMajorHookType.Set(value);
            }
        }

        [CategoryAttribute("Bottom Major Layer")]
        public FloorHookOrientations Bottom_Major_Hook_Orientation
        {
            get
            {
                int index = m_bottomMajorHookOrientation.AsInteger();
                return (FloorHookOrientations)index;
            }
            set
            {
                int index = (int)value;
                m_bottomMajorHookOrientation.Set(index);
            }
        }
        #endregion

        #region bottom minor layer
        [CategoryAttribute("Bottom Minor Layer"), TypeConverter(typeof(BarTypeItem))]
        public Autodesk.Revit.DB.ElementId Bottom_Minor_Bar_Type
        {
            get
            {
                return m_bottomMinorBarType.AsElementId();
            }
            set
            {
                m_bottomMinorBarType.Set(value);
            }
        }

        [CategoryAttribute("Bottom Minor Layer"), TypeConverter(typeof(HookTypeItem))]
        public Autodesk.Revit.DB.ElementId Bottom_Minor_Hook_Type
        {
            get
            {
                return m_bottomMinorHookType.AsElementId();
            }
            set
            {
                m_bottomMinorHookType.Set(value);
            }
        }

        [CategoryAttribute("Bottom Minor Layer")]
        public FloorHookOrientations Bottom_Minor_Hook_Orientation
        {
            get
            {
                int index = m_bottomMinorHookOrientation.AsInteger();
                return (FloorHookOrientations)index;
            }
            set
            {
                int index = (int)value;
                m_bottomMinorHookOrientation.Set(index);
            }
        }
        #endregion

    }
}

WallAreaReinData.cs

//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//


namespace Revit.SDK.Samples.AreaReinParameters.CS
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;
    using System.ComponentModel;

    using Autodesk.Revit;
    using Autodesk.Revit.DB;
    using Autodesk.Revit.DB.Structure;


    /// <summary>
    /// can be the datasource of propertygrid
    /// </summary>
    class WallAreaReinData : IAreaReinData
    {
        //member
        Parameter m_layoutRule;
        //exterior major layer
        Parameter m_exteriorMajorBarType = null;
        Parameter m_exteriorMajorHookType = null;
        Parameter m_exteriorMajorHookOrientation = null;

        //exterior minor layer
        Parameter m_exteriorMinorBarType = null;
        Parameter m_exteriorMinorHookType = null;
        Parameter m_exteriorMinorHookOrientation = null;

        //interior major layer
        Parameter m_interiorMajorBarType = null;
        Parameter m_interiorMajorHookType = null;
        Parameter m_interiorMajorHookOrientation = null;

        //interior minor layer
        Parameter m_interiorMinorBarType = null;
        Parameter m_interiorMinorHookType = null;
        Parameter m_interiorMinorHookOrientation = null;

        public bool FillInData(AreaReinforcement areaRein)
        {
            bool flag = true;

            //member
            m_layoutRule = areaRein.get_Parameter(
                BuiltInParameter.REBAR_SYSTEM_LAYOUT_RULE);
            flag = (m_layoutRule != null);

            ParameterSet paras = areaRein.Parameters;

            //exterior major layer
            m_exteriorMajorBarType = ParameterUtil.FindParaByName(paras, 
                "Exterior Major Bar Type");
            m_exteriorMajorHookType = ParameterUtil.FindParaByName(paras, 
                "Exterior Major Hook Type");
            m_exteriorMajorHookOrientation = ParameterUtil.FindParaByName(paras, 
                "Exterior Major Hook Orientation");
            flag &= (m_exteriorMajorBarType != null) && (m_exteriorMajorHookOrientation != null)
                && (m_exteriorMajorHookType != null);

            //exterior minor layer
            m_exteriorMinorBarType = ParameterUtil.FindParaByName(paras, 
                "Exterior Minor Bar Type");
            m_exteriorMinorHookType = ParameterUtil.FindParaByName(paras, 
                "Exterior Minor Hook Type");
            m_exteriorMinorHookOrientation = ParameterUtil.FindParaByName(paras, 
                "Exterior Minor Hook Orientation");
            flag &= (m_exteriorMinorBarType != null) && (m_exteriorMinorHookOrientation != null)
                && (m_exteriorMinorHookType != null);

            //interior major layer
            m_interiorMajorBarType = ParameterUtil.FindParaByName(paras, 
                "Interior Major Bar Type");
            m_interiorMajorHookType = ParameterUtil.FindParaByName(paras, 
                "Interior Major Hook Type");
            m_interiorMajorHookOrientation = ParameterUtil.FindParaByName(paras, 
                "Interior Major Hook Orientation");
            flag &= (m_interiorMajorBarType != null) && (m_interiorMajorHookOrientation != null)
                && (m_interiorMajorHookType != null);

            //interior minor layer
            m_interiorMinorBarType = ParameterUtil.FindParaByName(paras, 
                "Interior Minor Bar Type");
            m_interiorMinorHookType = ParameterUtil.FindParaByName(paras, 
                "Interior Minor Hook Type");
            m_interiorMinorHookOrientation = ParameterUtil.FindParaByName(paras, 
                "Interior Minor Hook Orientation");
            flag &= (m_interiorMinorBarType != null) && (m_interiorMinorHookOrientation != null)
                && (m_interiorMinorHookType != null);

            return flag;
        }

        [Category("Construction")]
        public LayoutRules Layout_Rule
        {
            get
            {
                int index = m_layoutRule.AsInteger();
                return (LayoutRules)index;
            }
            set
            {
                int index = (int)value;
                m_layoutRule.Set(index);
            }
        }

        #region exterior major layer
        [CategoryAttribute("Exterior Major Layers"), TypeConverter(typeof(BarTypeItem))]
        public Autodesk.Revit.DB.ElementId Exterior_Major_Bar_Type
        {
            get
            {
                return m_exteriorMajorBarType.AsElementId();
            }
            set
            {
                m_exteriorMajorBarType.Set(value);
            }
        }

        [CategoryAttribute("Exterior Major Layers"), TypeConverter(typeof(HookTypeItem))]
        public Autodesk.Revit.DB.ElementId Exterior_Major_Hook_Type
        {
            get
            {
                return m_exteriorMajorHookType.AsElementId();
            }
            set
            {
                m_exteriorMajorHookType.Set(value);
            }
        }

        [CategoryAttribute("Exterior Major Layers")]
        public WallHookOrientations Exterior_Major_Hook_Orientation
        {
            get
            {
                int index = m_exteriorMajorHookOrientation.AsInteger();
                return (WallHookOrientations)index;
            }
            set
            {
                int index = (int)value;
                m_exteriorMajorHookOrientation.Set(index);
            }
        }
        #endregion

        #region exterior minor layer
        [CategoryAttribute("Exterior Minor Layers"), TypeConverter(typeof(BarTypeItem))]
        public Autodesk.Revit.DB.ElementId Exterior_Minor_Bar_Type
        {
            get
            {
                return m_exteriorMinorBarType.AsElementId();
            }
            set
            {
                m_exteriorMinorBarType.Set(value);
            }
        }

        [CategoryAttribute("Exterior Minor Layers"), TypeConverter(typeof(HookTypeItem))]
        public Autodesk.Revit.DB.ElementId Exterior_Minor_Hook_Type
        {
            get
            {
                return m_exteriorMinorHookType.AsElementId();
            }
            set
            {
                m_exteriorMinorHookType.Set(value);
            }
        }

        [CategoryAttribute("Exterior Minor Layers")]
        public WallHookOrientations Exterior_Minor_Hook_Orientation
        {
            get
            {
                int index = m_exteriorMinorHookOrientation.AsInteger();
                return (WallHookOrientations)index;
            }
            set
            {
                int index = (int)value;
                m_exteriorMinorHookOrientation.Set(index);
            }
        }
        #endregion

        #region interior major layer
        [CategoryAttribute("Interior Major Layers"), TypeConverter(typeof(BarTypeItem))]
        public Autodesk.Revit.DB.ElementId Interior_Major_Bar_Type
        {
            get
            {
                return m_interiorMajorBarType.AsElementId();
            }
            set
            {
                m_interiorMajorBarType.Set(value);
            }
        }

        [CategoryAttribute("Interior Major Layers"), TypeConverter(typeof(HookTypeItem))]
        public Autodesk.Revit.DB.ElementId Interior_Major_Hook_Type
        {
            get
            {
                return m_interiorMajorHookType.AsElementId();
            }
            set
            {
                m_interiorMajorHookType.Set(value);
            }
        }

        [CategoryAttribute("Interior Major Layers")]
        public WallHookOrientations Interior_Major_Hook_Orientation
        {
            get
            {
                int index = m_interiorMajorHookOrientation.AsInteger();
                return (WallHookOrientations)index;
            }
            set
            {
                int index = (int)value;
                m_interiorMajorHookOrientation.Set(index);
            }
        }
        #endregion

        #region interior minor layer
        [CategoryAttribute("Interior Minor Layers"), TypeConverter(typeof(BarTypeItem))]
        public Autodesk.Revit.DB.ElementId Interior_Minor_Bar_Type
        {
            get
            {
                return m_interiorMinorBarType.AsElementId();
            }
            set
            {
                m_interiorMinorBarType.Set(value);
            }
        }

        [CategoryAttribute("Interior Minor Layers"), TypeConverter(typeof(HookTypeItem))]
        public Autodesk.Revit.DB.ElementId Interior_Minor_Hook_Type
        {
            get
            {
                return m_interiorMinorHookType.AsElementId();
            }
            set
            {
                m_interiorMinorHookType.Set(value);
            }
        }

        [CategoryAttribute("Interior Minor Layers"),]
        public WallHookOrientations Interior_Minor_Hook_Orientation
        {
            get
            {
                int index = m_interiorMinorHookOrientation.AsInteger();
                return (WallHookOrientations)index;
            }
            set
            {
                int index = (int)value;
                m_interiorMinorHookOrientation.Set(index);
            }
        }
        #endregion

    }
}

ParameterUtil.cs

//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//


namespace Revit.SDK.Samples.AreaReinParameters.CS
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;

    using Autodesk.Revit;
    using Autodesk.Revit.DB;

    /// <summary>
    /// contain utility methods find or set certain parameter
    /// </summary>
    public class ParameterUtil
    {
        private ParameterUtil()
        {
        }

        /// <summary>
        /// find certain parameter in a set
        /// </summary>
        /// <param name="paras"></param>
        /// <param name="name">find by name</param>
        /// <returns>found parameter</returns>
        public static bool SetParaInt(Element elem, string paraName, int value)
        {
            ParameterSet paras = elem.Parameters;
            Parameter findPara = FindParaByName(paras, paraName);

            if (null == findPara)
            {
                return false;
            }

            if (!findPara.IsReadOnly)
            {
                findPara.Set(value);
                return true;
            }

            return false;
        }

        /// <summary>
        /// find certain parameter in a set
        /// </summary>
        /// <param name="paras"></param>
        /// <param name="name">find by name</param>
        /// <returns>found parameter</returns>
        public static Parameter FindParaByName(ParameterSet paras, string name)
        {
            Parameter findPara = null;

            foreach (Parameter para in paras)
            {
                if (para.Definition.Name == name)
                {
                    findPara = para;
                }
            }

            return findPara;
        }

        /// <summary>
        /// set certain parameter of given element to int value
        /// </summary>
        /// <param name="elem">given element</param>
        /// <param name="paraIndex">BuiltInParameter</param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool SetParaInt(Element elem, BuiltInParameter paraIndex, int value)
        {
            Parameter para = elem.get_Parameter(paraIndex);
            if (null == para)
            {
                return false;
            }

            if (!para.IsReadOnly)
            {
                para.Set(value);
                return true;
            }

            return false;
        }

        /// <summary>
        /// set certain parameter of given element to int value
        /// </summary>
        /// <param name="elem">given element</param>
        /// <param name="paraIndex">BuiltInParameter</param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool SetParaNullId(Parameter para)
        {
            Autodesk.Revit.DB.ElementId id = new ElementId(-1);

            if (!para.IsReadOnly)
            {
                para.Set(id);
                return true;
            }
            return false;
        }
    }
}