TestExport.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:TestExport
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/18 15:43:54
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using Autodesk.Revit.Attributes;
  14. using Autodesk.Revit.DB;
  15. using Autodesk.Revit.DB.Plumbing;
  16. using Autodesk.Revit.UI;
  17. using RevitExport;
  18. using RevitToJBim.ComponentParse;
  19. using SAGA.RevitUtils;
  20. using SAGA.RevitUtils.Extends;
  21. namespace RevitToJBim
  22. {
  23. public class TestExport
  24. {
  25. public static Document Document { get; set; }
  26. public static void Export()
  27. {
  28. var elements = Document.GetElements(typeof(Pipe));
  29. var wrappers = elements.Select(e => new ElementWrapper(e)).ToList();
  30. ExportInstance report = new ExportInstance(wrappers);
  31. JBimParseContext context = new JBimParseContext(ParseCore.GetUseParsers());
  32. var dd = false;
  33. context.Parser.Parse(report);
  34. var result = context.Serialize();
  35. string fileName = DateTime.Now.ToString("yyyyMMddhhmmss");
  36. string path = Path.Combine(@"D:\", $"{fileName}.json");
  37. File.WriteAllText(path, result);
  38. }
  39. }
  40. /// <summary>
  41. /// 增加缺失元空间
  42. /// </summary>
  43. [Transaction(TransactionMode.Manual)]
  44. [Regeneration(RegenerationOption.Manual)]
  45. public class AddSiSpaceCommand : IExternalCommand, IExternalCommandAvailability
  46. {
  47. public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  48. {
  49. try
  50. {
  51. TestExport.Document = commandData.Application.ActiveUIDocument.Document;
  52. TestExport.Export();
  53. TaskDialog dialog = new TaskDialog("导出");
  54. dialog.MainInstruction ="导出成功";
  55. dialog.Show();
  56. }
  57. catch (Exception e)
  58. {
  59. TaskDialog dialog = new TaskDialog("导出");
  60. dialog.MainInstruction =e.Message+"\n\t"+ e.StackTrace.ToString();
  61. dialog.Show();
  62. return Result.Cancelled;
  63. }
  64. return Result.Succeeded;
  65. }
  66. /// <summary>
  67. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  68. /// when a document is open.
  69. /// </summary>
  70. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  71. {
  72. return false;
  73. }
  74. }
  75. }