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;
        }
    }
}

运行结果

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值