RoomDataToSpaceCommand.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:RoomDataToSpace
  3. * 作者:xulisong
  4. * 创建时间: 2019/7/26 10:14:55
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Diagnostics;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using Autodesk.Revit.Attributes;
  16. using Autodesk.Revit.DB;
  17. using Autodesk.Revit.UI;
  18. using FWindSoft.Revit;
  19. using FWindSoft.Revit.Menu;
  20. namespace LRH.Tool
  21. {
  22. [Transaction(TransactionMode.Manual)]
  23. [Regeneration(RegenerationOption.Manual)]
  24. [Button(ButtonName = "房间数据\r\n赋值到空间")]
  25. public class RoomDataToSpaceCommand : ExternalCommand
  26. {
  27. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  28. {
  29. var document = commandData.Application.ActiveUIDocument.Document;
  30. var view = document.ActiveView;
  31. if (view is View3D)
  32. {
  33. MessageBox.Show("指定导出平面视图");
  34. return Result.Succeeded;
  35. }
  36. using (Transaction tran = new Transaction(RevitCore.Doc, "创建空间"))
  37. {
  38. try
  39. {
  40. tran.Start();
  41. var list = RoomToSpaceUtils.RoomDataToSpace(view);
  42. if (list.All(r => r.IsSuccess))
  43. {
  44. MessageBox.Show("赋值成功");
  45. }
  46. else
  47. {
  48. MessageBox.Show("部分赋值成功");
  49. var text = RoomToSpaceUtils.CreateResult(list).ToString();
  50. string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "result.txt");
  51. File.WriteAllText(path, text);
  52. Process.Start("notepad.exe", path);
  53. }
  54. tran.Commit();
  55. }
  56. catch (Exception e)
  57. {
  58. tran.RollBack();
  59. throw;
  60. }
  61. }
  62. return Result.Succeeded;
  63. }
  64. }
  65. }