Revit二次开发 - 获取墙的厚度和高度

获取Revit文件中,墙的相关属性信息。

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Collections.Generic;
using System.Windows.Forms;

namespace RevitAddin2
{
    [TransactionAttribute(TransactionMode.Manual)]
    public class RevitAddin : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            Autodesk.Revit.DB.Document doc = uiApp.ActiveUIDocument.Document;

            FilteredElementCollector collector = new FilteredElementCollector(doc);
            collector.WherePasses(new ElementClassFilter(typeof(Wall)));
            IList<Element> walls = collector.ToElements();

            string result = "";
            foreach (Element item in walls)
            {
                Wall wall = item as Wall;
                if (null != wall)
                {               
                    double height = 0.0;
                    foreach (Parameter param in wall.Parameters)
                    {
                        InternalDefinition definition = param.Definition as InternalDefinition;
                        if (null == definition)
                            continue;

                        if (BuiltInParameter.WALL_USER_HEIGHT_PARAM == definition.BuiltInParameter)
                        {
                            height = param.AsDouble();
                        }
                    }
                    result += "type:" + wall.WallType.Name + " ";
                    result += "width:" + FeetTomm(wall.Width) + " ";
                    result += "height:" + FeetTomm(height) + "\n";
                }             
            }
            MessageBox.Show(result);
            return Result.Succeeded;
        }

        //1英尺 = 304.8毫米
        public static double FeetTomm(double val)
        {
            return val * 304.8;
        }
    }
}

运行结果

猜你喜欢

转载自blog.csdn.net/liyazhen2011/article/details/87286885