Kaynağa Gözat

xls:墙轮廓线,类型分组序列化

xulisong 5 yıl önce
ebeveyn
işleme
4394866b5b

+ 16 - 4
JBIM/RevitToJBim/Extension/WallExtension.cs

@@ -22,16 +22,28 @@ namespace RevitToJBim.Extension
         public static List<PlanarFace> GetTopFaces(this Wall wall)
         {
             var solids = Extension.GeometryElementExtension.GetSolids(wall, wall.Document.GetUseView());
-            var topZ = wall.GetTopStaticHeight();
+            //var topZ = wall.GetTopStaticHeight();
+            //比较最大值不靠谱,取当前面中高度最高的
+            double topZ = double.MinValue;
             List<PlanarFace> faces = new List<PlanarFace>();
             foreach (var solid in solids)
             {
                 foreach (Face face in solid.Faces)
                 {
-                    if (face is PlanarFace planarFace && planarFace.FaceNormal == XYZ.BasisZ && planarFace.Origin.Z.IsEqual(topZ))
+                    if (face is PlanarFace planarFace && planarFace.FaceNormal.IsEqual(XYZ.BasisZ))
                     {
-
-                        faces.Add(planarFace);
+                        var tempZ = planarFace.Origin.Z;
+                        if (tempZ.IsThan(topZ))
+                        {
+                            faces.Clear();
+                            topZ = tempZ;
+                            faces.Add(planarFace);
+                        }
+                        else if(tempZ.IsEqual(topZ))
+                        {
+                            faces.Add(planarFace);
+                        }
+                       
                     }
                 }
             }

+ 10 - 7
JBIM/RevitToJBim/JsonConverter/BimJsonUtil.cs

@@ -13,6 +13,7 @@ using System.Threading.Tasks;
 using JBIM;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Converters;
+using Newtonsoft.Json.Linq;
 
 namespace RevitToJBim.JsonConverter
 {
@@ -26,14 +27,16 @@ namespace RevitToJBim.JsonConverter
             //jsetting.Converters.Add(new XYZConverter());
             jsetting.Converters.Add(new StringEnumConverter());
             jsetting.Converters.Add(new ParameterConverter());
-            //var serializer = JsonSerializer.Create(jsetting);
-            //JObject jobject = new JObject();
-            //foreach (var collection in m_DataSource)
-            //{
-            //    jobject.Add(collection.Key, JArray.FromObject(collection.Value, serializer));
-            //}
+            var bimObjects = document.BimObjects;
+            var group = bimObjects.GroupBy(bim => bim.ElementType);
+            Dictionary<string, List<BimObject>> dic = new Dictionary<string, List<BimObject>>();
+            foreach (var collection in group)
+            {
+                dic[collection.Key + "s"] = collection.ToList();
+                //jobject.Add(collection.Key, JArray.FromObject(collection.Value, serializer));
+            }
             //var settings = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore };
-            string dataStr = JsonConvert.SerializeObject(document.BimObjects, jsetting);
+            string dataStr = JsonConvert.SerializeObject(dic, jsetting);
             return dataStr;
         }
     }