MBIDocument.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:MBIDocument
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/28 10:57:07
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Autodesk.Revit.DB;
  13. using JBIM;
  14. using Newtonsoft.Json.Linq;
  15. using SAGA.DotNetUtils.Extend;
  16. using SAGA.RevitUtils;
  17. using SAGA.RevitUtils.Extends;
  18. namespace RevitToJBim.MBI
  19. {
  20. /// <summary>
  21. /// 项目传输数据结构
  22. /// </summary>
  23. public class MBIDocument
  24. {
  25. public string MBIName { get; set; }
  26. public string ModelId { get; set; }
  27. public string PlanName { get; set; }
  28. public double BaseLevel { get; set; }
  29. public Dictionary<string, List<BimObject>> Elements { get; private set; }
  30. /// <summary>
  31. /// 附加元素Elements信息
  32. /// </summary>
  33. /// <param name="document"></param>
  34. public void AttachElements(BimDocument document)
  35. {
  36. var bimObjects = document.BimObjects;
  37. var group = bimObjects.GroupBy(bim => bim.ElementType);
  38. Dictionary<string, List<BimObject>> dic = new Dictionary<string, List<BimObject>>();
  39. foreach (var collection in group)
  40. {
  41. dic[collection.Key + "s"] = collection.ToList();
  42. }
  43. Elements = dic;
  44. }
  45. public static MBIDocument CreateDocument(Document document, string param)
  46. {
  47. MBIDocument dto = new MBIDocument();
  48. JObject jObject = JObject.Parse(param);
  49. dto.MBIName = jObject.GetValueEx("MBIName");//待读取
  50. dto.ModelId = jObject.GetValueEx("ModelId");
  51. #if DEBUG
  52. //dto.MBIName = "Pj1101010038";//待读取
  53. //dto.ModelId = "47e62800220811ea962a7d2b043144ce";
  54. #endif
  55. dto.PlanName = document.GetUseView()?.Name;
  56. dto.BaseLevel = document.GetUseView()?.GenLevel.Elevation.FromApi().Round(2)??0;
  57. return dto;
  58. }
  59. }
  60. }