/*------------------------------------------------------------------------- * 功能描述:RoomDataToSpace * 作者:xulisong * 创建时间: 2019/7/26 10:14:55 * 版本号:v1.0 * -------------------------------------------------------------------------*/ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using FWindSoft.Revit; using FWindSoft.Revit.Menu; namespace LRH.Tool { [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] [Button(ButtonName = "房间数据\r\n赋值到空间")] public class RoomDataToSpaceCommand : ExternalCommand { public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var document = commandData.Application.ActiveUIDocument.Document; var view = document.ActiveView; if (view is View3D) { MessageBox.Show("指定导出平面视图"); return Result.Succeeded; } using (Transaction tran = new Transaction(RevitCore.Doc, "创建空间")) { try { tran.Start(); var list = RoomToSpaceUtils.RoomDataToSpace(view); if (list.All(r => r.IsSuccess)) { MessageBox.Show("赋值成功"); } else { MessageBox.Show("部分赋值成功"); var text = RoomToSpaceUtils.CreateResult(list).ToString(); string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "result.txt"); File.WriteAllText(path, text); Process.Start("notepad.exe", path); } tran.Commit(); } catch (Exception e) { tran.RollBack(); throw; } } return Result.Succeeded; } } }