ParseDuct.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:ParseDuct
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/20 9:40:13
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using Autodesk.Revit.DB;
  8. using Autodesk.Revit.DB.Mechanical;
  9. using JBIM;
  10. using JBIM.Definition;
  11. using RevitExport.Export;
  12. using RevitToJBim.Common;
  13. using RevitToJBim.ParseData;
  14. using SAGA.RevitUtils.Extends;
  15. using SAGA.RevitUtils.MEP;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using JDuct = JBIM.Component.Duct;
  20. using JDuctShape = JBIM.Definition.DuctShape;
  21. using XYZ = JBIM.Definition.XYZ;
  22. namespace RevitToJBim.ComponentParse
  23. {
  24. [UsableParse]
  25. public class ParseDuct : ParseBase
  26. {
  27. public override List<string> FastIndex()
  28. {
  29. return new List<string>() { typeof(Duct).FullName };
  30. }
  31. public override bool Match(ElementWrapper wrapper)
  32. {
  33. return wrapper.RefElement is Duct;
  34. }
  35. protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
  36. {
  37. if (!(wrapper.RefElement is Duct duct))
  38. {
  39. return null;
  40. }
  41. JDuct jDuct = new JDuct();
  42. ParseCore.AttachObject(jDuct, wrapper);
  43. var locations = new List<XYZ>();
  44. locations.Add(BimConvert.ConvertToXYZ(duct.GetCurve().StartPoint()));
  45. locations.Add(BimConvert.ConvertToXYZ(duct.GetCurve().EndPoint()));
  46. jDuct.Location = GeometryLocation.CreateLineLocation(locations);
  47. Polygon outLine = new Polygon(locations);
  48. jDuct.OutLine.Add(outLine);
  49. context.AddBimObject(jDuct);
  50. //Parameters
  51. jDuct.Parameters = RevitUtil.GetMEPCurveParameters(duct);
  52. #region 关联数据处理相关
  53. #region 系统关系
  54. var pipeId = duct.Id.ToString();
  55. try
  56. {
  57. var systemTypeName = duct.Document.GetElement(duct.MEPSystem?.GetTypeId());
  58. jDuct.MepSystemTypeName = systemTypeName?.Name;
  59. }
  60. catch (Exception e)
  61. {
  62. Console.WriteLine(e.Message+e.StackTrace);
  63. }
  64. #endregion
  65. ConnectorProfileType shape = ConnectorProfileType.Invalid;
  66. #region Connector连接关系
  67. var connectors = duct.GetConnectors(Autodesk.Revit.DB.Domain.DomainHvac);
  68. ElementOneToManyRel relMany = new ElementOneToManyRel(pipeId) { RelatedObjects = new List<string>() };
  69. relMany.SetElementType(TypeDefinition.Property_ConnectedIds);
  70. foreach (var refConnector in connectors)
  71. {
  72. relMany.RelatedObjects.Add(RevitIdGenerator.GetConnectorId(refConnector));
  73. shape = refConnector.Shape;
  74. }
  75. if (relMany.RelatedObjects.Any())
  76. {
  77. context.RelationShips.Add(relMany);
  78. }
  79. #endregion
  80. if (shape== ConnectorProfileType.Round)
  81. {//duct.
  82. jDuct.Diameter = duct.Diameter.FtToUse();
  83. }
  84. else
  85. {
  86. jDuct.Width = duct.Width.FtToUse();
  87. jDuct.Height = duct.Height.FtToUse();
  88. }
  89. jDuct.Shape = (JDuctShape) (int) shape;
  90. #endregion
  91. return new List<BimId>() { jDuct.Id };
  92. }
  93. public override List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)
  94. {
  95. if (!(wrapper.RefElement is Duct duct))
  96. {
  97. return null;
  98. }
  99. var wrappers = new List<ElementWrapper>() { };
  100. var connectors = duct.GetConnectors(Autodesk.Revit.DB.Domain.DomainHvac);
  101. foreach (var connector in connectors)
  102. {
  103. wrappers.Add(ParseCore.GetConnectorWrapper(connector));
  104. }
  105. return wrappers;
  106. }
  107. }
  108. }