Ver código fonte

xls:提交合并

xulisong 5 anos atrás
pai
commit
76c330867e
1 arquivos alterados com 72 adições e 13 exclusões
  1. 72 13
      JBIM/RevitToJBim/Common/RevitUtil.cs

+ 72 - 13
JBIM/RevitToJBim/Common/RevitUtil.cs

@@ -6,7 +6,6 @@
  *  -------------------------------------------------------------------------*/
 
 using Autodesk.Revit.DB;
-using SAGA.RevitUtils;
 using SAGA.RevitUtils.Extends;
 using SAGA.RevitUtils.Extends.Graphic;
 using System;
@@ -14,6 +13,11 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using RevitToJBim.Extension;
+using RevitToJBim.MBI;
+using SAGA.DotNetUtils;
+using Parameter=JBIM.Component.Parameter;
+using SAGA.RevitUtils;
 
 namespace RevitToJBim.Common
 {
@@ -44,6 +48,63 @@ namespace RevitToJBim.Common
 
             return path;
         }
+        /// <summary>
+        /// 获取FamilyInstance box底面轮廓
+        /// </summary>
+        /// <param name="fi"></param>
+        /// <returns></returns>
+        public static List<XYZ> GetBottomPolygon(FamilyInstance fi)
+        {
+            List<XYZ> path=new List<XYZ>();
+            var box = fi.get_BoundingBox(null);
+            if (box == null) return path;
+            var boxMin = box.Min;
+            var boxMax = box.Max;
+            path.Add(boxMin);
+            path.Add(boxMin.NewX(boxMax.X));
+            path.Add(boxMin.NewX(boxMax.X).NewY(boxMax.Y));
+            path.Add(boxMin.NewY(boxMax.Y));
+            path.Add(boxMin);
+            return path;
+        }
+        /// <summary>
+        /// 获取设备设施的参数
+        /// </summary>
+        /// <param name="fi"></param>
+        /// <returns></returns>
+        public static List<Parameter> GetFacilityParameters(FamilyInstance fi)
+        {
+            List<string> parameterNames=new List<string>(){ MBIBuiltInParameterName.EquipLocalName,MBIBuiltInParameterName.EquipLocalID };
+            List<Parameter> parameters=new List<Parameter>();
+            foreach (var parameterName in parameterNames)
+            {
+                var revitParameter = fi.GetParameter(parameterName);
+                if (revitParameter != null)
+                {
+                    var parameter = new Parameter(ParameterUtil.FindParameterDefine(parameterName));
+                    parameter.Value = revitParameter.AsString();
+                    parameters.Add(parameter);
+                }
+            }
+
+            return parameters;
+        }
+
+        /// <summary>
+        /// 获取部件所关联的设备
+        /// </summary>
+        /// <param name="element"></param>
+        /// <returns></returns>
+        public static Element GetEquipPartParent(Element element)
+        {
+            if (!element.IsEquipmentPart()) return null;
+            string code = element.GetFamilyName()?.Substring(0, 4); ;
+            if (code.IsNullOrEmpty()) return null;
+            //构件所关联的设备
+            var parentInst = element.Document.GetElements(new ElementIntersectsElementFilter(element))
+                .FirstOrDefault(t => !t.Id.IsEqual(element.Id) && t.GetFamilyCode() == code);
+            return parentInst;
+        }
 
         /// <summary>
         /// 获取门窗到墙线上的投影线
@@ -69,13 +130,13 @@ namespace RevitToJBim.Common
                 location = xyzs.FirstOrDefault();
             }
 
-            double min=0, max=0;
-            XYZ minXYZ=XYZ.Zero, maxXYZ = XYZ.Zero;
+            double min = 0, max = 0;
+            XYZ minXYZ = XYZ.Zero, maxXYZ = XYZ.Zero;
             for (int i = 0; i < xyzs.Count; i++)
             {
                 var usePoint = xyzs[i];
                 var refDirection = usePoint - location;
-                var offset= refDirection.DotProduct(handDirection);
+                var offset = refDirection.DotProduct(handDirection);
                 #region 初始化逻辑
                 if (i == 0)
                 {
@@ -88,8 +149,8 @@ namespace RevitToJBim.Common
                 {
                     if (offset < min)
                     {
-                        minXYZ =  usePoint;
-                        min =  offset;
+                        minXYZ = usePoint;
+                        min = offset;
                         continue;
                     }
                     if (max < offset)
@@ -98,10 +159,10 @@ namespace RevitToJBim.Common
                         max = offset;
                         continue;
                     }
-                } 
+                }
                 #endregion
             }
-            return new List<XYZ>(){minXYZ,maxXYZ};
+            return new List<XYZ>() { minXYZ, maxXYZ };
         }
 
         /// <summary>
@@ -111,7 +172,7 @@ namespace RevitToJBim.Common
         public static List<XYZ> GetVertexPoints(Element element)
         {
             List<XYZ> xyzs = new List<XYZ>();
-            var solids=element.GetSolids();
+            var solids = element.GetSolids();
             foreach (var solid in solids)
             {
                 foreach (Edge edge in solid.Edges)
@@ -136,9 +197,9 @@ namespace RevitToJBim.Common
              */
             var curve = wall.GetLocationCurve();
 
-            
+
             List<List<XYZ>> polygons = new List<List<XYZ>>();
-            var refs = HostObjectUtils.GetSideFaces(wall,ShellLayerType.Exterior).OfType<Face>();
+            var refs = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Exterior).OfType<Face>();
             foreach (Face face in refs)
             {
                 List<XYZ> polygon = new List<XYZ>();
@@ -151,7 +212,5 @@ namespace RevitToJBim.Common
             //偏移位位置信息
             return polygons;
         }
-
-      
     }
 }