获取墙的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;
}
}
}