Revit二次开发之获取元素的内部信息

获取墙的Location

                //var location = wall.Location as LocationPoint;
                //var point = location.Point;
                //var start = curve.GetEndPoint(0);
                //var end = curve.GetEndPoint(1);
                //var length =UnitUtils.ConvertFromInternalUnits(curve.Length,DisplayUnitType.DUT_MILLIMETERS);
                //var length1 = curve.Length * 304.8;

                //TaskDialog.Show("BIMBOX", $"选择墙的起点是{start.ToString()}\n终点是{end.ToString()}\n长度是{length}mm或者是{length1}mm");

 Revit内置API对于尺寸的转换

//将英尺转换为Revit所设定的毫米
var length=UnitUtils.ConvertFromInternalUnits(curve.Length, DisplayUnitType.DUT_MILLIMETERS);

拓展方法和递归函数的使用

获取元素并且遍历几何对象

 

 调用扩展方法与其他一致(扩展方法图标在原有方法图标的右下角有个向下的箭头呦)

var geometryObjects = door.GetGeometryObjects();

非几何信息的获取

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using NPOI.HSSF.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ClassLibrary1
{
    [Transaction(TransactionMode.Manual)]
    [Journaling(JournalingMode.NoCommandData)]
    [Regeneration(RegenerationOption.Manual)]
    public class GetRoomInfo : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uiDoc = commandData.Application.ActiveUIDocument;
            Document doc = uiDoc.Document;
            Selection sel = uiDoc.Selection;
            Autodesk.Revit.DB.View activeView = uiDoc.ActiveView;
            var collector=new FilteredElementCollector(doc).OfClass(typeof(SpatialElement)).ToElements();
            var roomInfoList=new List<List<string>>();
            foreach (Room item in collector)
            {
                var name=item.Name;
                var area=item.Area.ToString();
                var levelName = item.Level.Name;
                var parameter=item.get_Parameter(BuiltInParameter.ROOM_HEIGHT).AsValueString();
                //var roomHight=parameter.AsValueString();
                var roomInfo = new List<string> { name, area,levelName,parameter };
                roomInfoList.Add(roomInfo);
            }
            var workbook = new HSSFWorkbook();
            var sheet = workbook.CreateSheet("房间信息");
            var hesders = new string[] { "房间名称", "房间面积", "房间所在标高", "房间标示高度" };
            var row0 = sheet.CreateRow(0);
            for (int i = 0; i < hesders.Count(); i++)
            {
                var cell = row0.CreateCell(i);
                cell.SetCellValue(hesders[i]);
            }
            for (int i = 0; i < roomInfoList.Count; i++)
            {
                var row = sheet.CreateRow(i + 1);
                for (int j = 0; j < roomInfoList[i].Count; j++)
                {
                    var cell = row.CreateCell(j);
                    cell.SetCellValue(roomInfoList[i][j]);
                }
            }
            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Filter = "(Excel文件)|*.xls";
            fileDialog.FileName = "房间信息统计";
            bool isFileOk = false;
            fileDialog.FileOk += (s, e) => { isFileOk = true; };
            fileDialog.ShowDialog();
            if (isFileOk)
            {
                var path = fileDialog.FileName;
                using (var fs = File.OpenWrite(path))
                {
                    workbook.Write(fs);
                    MessageBox.Show($"文件成功保存至{fileDialog.FileName}", "BIMBOX");
                }
            }


            return Result.Succeeded;
        }
    }
}

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值