Browse Source

xls:风管信息

xulisong 5 years ago
parent
commit
db2ecfdf9e

+ 3 - 3
JBIM/JBIM/Definition/ConnectorShape.cs

@@ -28,9 +28,9 @@ namespace JBIM
     /// </summary>
     public enum DuctShape
     {
-        Circle=1,
-        Rectangle=2,
-        Ellipse=3
+        Circle=0,
+        Rectangle=1,
+        Ellipse=2
     }
 
     public enum ConnectorDomain

+ 9 - 0
JBIM/RevitToJBim/Common/Converter.cs

@@ -23,6 +23,15 @@ namespace RevitToJBim.Common
         {
             return Math.Round(coordinateDecimal, CoordinateDecimalDigits);
         }
+        /// <summary>
+        /// 英尺转换成现在阶段使用单位
+        /// </summary>
+        /// <param name="footValue"></param>
+        /// <returns></returns>
+        public static double FtToUse(this double footValue)
+        {
+            return Round(footValue.FromApi());
+        }
         public static XYZ ConvertToXYZ(Autodesk.Revit.DB.XYZ xyz)
         {
             return new XYZ() {X = Round(xyz.X.FromApi()), Y = Round(xyz.Y.FromApi()), Z = Round(xyz.Z.FromApi()),};

+ 108 - 0
JBIM/RevitToJBim/ComponentParse/ParseDuct.cs

@@ -0,0 +1,108 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ParseDuct
+ * 作者:xulisong
+ * 创建时间: 2019/6/20 9:40:13
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using Autodesk.Revit.DB.Mechanical;
+using Autodesk.Revit.DB.Plumbing;
+using JBIM;
+using RevitExport;
+using RevitToJBim.Common;
+using SAGA.RevitUtils.Extends;
+using SAGA.RevitUtils.MEP;
+using JDuctShape = JBIM.DuctShape;
+using JDuct = JBIM.Component.Duct;
+using XYZ = JBIM.XYZ;
+
+namespace RevitToJBim.ComponentParse
+{
+    [UsableParse]
+    public class ParseDuct : ParseBase
+    {
+        public override List<string> FastIndex()
+        {
+            return new List<string>() { typeof(Duct).FullName };
+        }
+        public override bool Match(ElementWrapper wrapper)
+        {
+            return wrapper.RefElement is Duct;
+        }
+
+        protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
+        {
+            if (!(wrapper.RefElement is Duct duct))
+            {
+                return null;
+            }
+            JDuct jDuct = new JDuct();
+            ParseCore.AttachObject(jDuct, wrapper);           
+            var locations = new List<XYZ>();
+            locations.Add(BimConvert.ConvertToXYZ(duct.GetCurve().StartPoint()));
+            locations.Add(BimConvert.ConvertToXYZ(duct.GetCurve().EndPoint()));
+            jDuct.Location = GeometryLocation.CreateLineLocation(locations);
+            Polygon outLine = new Polygon(locations);
+            jDuct.OutLine.Add(outLine);
+            context.AddBimObject(jDuct);
+            #region 关联数据处理相关
+            #region 系统关系
+            var pipeId = duct.Id.ToString();
+            var systemTypeName = duct.Document.GetElement(duct.MEPSystem.GetTypeId());
+            jDuct.MepSystemTypeName = systemTypeName.Name;
+            #endregion
+
+            ConnectorProfileType shape = ConnectorProfileType.Invalid;
+            #region Connector连接关系
+            var connectors = duct.GetConnectors(Autodesk.Revit.DB.Domain.DomainHvac);
+            ElementOneToManyRel relMany = new ElementOneToManyRel(pipeId) { RelatedObjects = new List<string>() };
+            relMany.SetElementType(TypeDefinition.Property_ConnectedIds);
+            foreach (var refConnector in connectors)
+            {
+                relMany.RelatedObjects.Add(RevitIdGenerator.GetConnectorId(refConnector));
+                shape = refConnector.Shape;
+            }
+
+            if (relMany.RelatedObjects.Any())
+            {
+                context.RelationShips.Add(relMany);
+            }
+            #endregion
+
+            if (shape== ConnectorProfileType.Round)
+            {//duct.
+                jDuct.Diameter = duct.Diameter.FtToUse();
+            }
+            else
+            {
+                jDuct.Width = duct.Width.FtToUse();
+                jDuct.Height = duct.Height.FtToUse();
+            }
+
+            jDuct.Shape = (JDuctShape) (int) shape;
+            #endregion
+            return new List<BimId>() { jDuct.Id };
+        }
+
+        public override List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)
+        {
+            if (!(wrapper.RefElement is Duct duct))
+            {
+                return null;
+            }   
+            var wrappers = new List<ElementWrapper>() { };
+            var connectors = duct.GetConnectors(Autodesk.Revit.DB.Domain.DomainHvac);
+            foreach (var connector in connectors)
+            {
+                wrappers.Add(ParseCore.GetConnectorWrapper(connector));
+            }
+            return wrappers;
+        }
+    }
+}

+ 2 - 2
JBIM/RevitToJBim/ComponentParse/ParseMepSystem.cs

@@ -19,7 +19,7 @@ using JMepSystem = JBIM.Component.MepSystem;
 using JMepSystemType = JBIM.Component.MepSystemType;
 namespace RevitToJBim.ComponentParse
 {
-    [UsableParse]
+    //[UsableParse]
     public class ParseMepSystem : ParseBase
     {
         public override List<string> FastIndex()
@@ -49,7 +49,7 @@ namespace RevitToJBim.ComponentParse
             return new List<BimId>() { jBimObject.Id };
         }
     }
-    [UsableParse]
+    //[UsableParse]
     public class ParseMepSystemType : ParseBase
     {
         public override List<string> FastIndex()

+ 1 - 1
JBIM/RevitToJBim/ComponentParse/ParsePipe.cs

@@ -45,7 +45,7 @@ namespace RevitToJBim.ComponentParse
             }
             JPipe jPipe = new JPipe();
             ParseCore.AttachObject(jPipe, wrapper);
-            jPipe.Diameter = BimConvert.Round(pipe.Diameter.FromApi());
+            jPipe.Diameter =pipe.Diameter.FtToUse();
             var locations = new List<XYZ>();
             locations.Add(BimConvert.ConvertToXYZ(pipe.GetCurve().StartPoint()));
             locations.Add(BimConvert.ConvertToXYZ(pipe.GetCurve().EndPoint()));

+ 1 - 0
JBIM/RevitToJBim/RevitToJBim.csproj

@@ -65,6 +65,7 @@
     <Compile Include="ComponentParse\ParseBase.cs" />
     <Compile Include="ComponentParse\ParseConnector.cs" />
     <Compile Include="ComponentParse\ParseCore.cs" />
+    <Compile Include="ComponentParse\ParseDuct.cs" />
     <Compile Include="ComponentParse\ParseMepSystem.cs" />
     <Compile Include="ComponentParse\ParsePipe.cs" />
     <Compile Include="ComponentParse\ParseSpace.cs" />

+ 3 - 1
JBIM/RevitToJBim/TestExport.cs

@@ -30,14 +30,16 @@ namespace RevitToJBim
         {
             var elements = Document.GetElements(typeof(Pipe));
             var elements2 = Document.GetElements(typeof(SpatialElement)).OfType<Space>().ToList();
+            var elements3 = Document.GetElements(typeof(Duct)).OfType<Duct>().ToList();
             elements.AddRange(elements2);
+            elements.AddRange(elements3);
             var wrappers = elements.Select(e => new ElementWrapper(e)).ToList();
             ExportInstance report = new ExportInstance(wrappers);
             JBimParseContext context = new JBimParseContext(ParseCore.GetUseParsers());
             var dd = false;
             context.Parser.Parse(report);
             var result = context.Serialize();
-            string fileName = DateTime.Now.ToString("yyyyMMddhhmmss");
+            string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
             string path = Path.Combine(@"D:\", $"{fileName}.json");
             File.WriteAllText(path, result);
         }