MBIDocument.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. //dto.MBIName = "Pj1101010015";//待读取
  52. //dto.ModelId = "6d8642d9d92a11e98e2d2108fa0baa21";
  53. dto.PlanName = document.GetUseView()?.Name;
  54. dto.BaseLevel = document.GetUseView()?.GenLevel.Elevation.FromApi().Round(2)??0;
  55. return dto;
  56. }
  57. }
  58. }