12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- /*-------------------------------------------------------------------------
- * 功能描述:BimJsonUtil
- * 作者:xulisong
- * 创建时间: 2019/6/18 11:23:16
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using JBIM;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Converters;
- using Newtonsoft.Json.Linq;
- namespace RevitToJBim.JsonConverter
- {
- public static class BimJsonUtil
- {
- public static string Serializer(BimDocument document)
- {
- JsonSerializerSettings jsetting = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore };
- jsetting.Converters.Add(new BimIdConverter());
- //mxg 显示x:,y:,z:格式的
- //jsetting.Converters.Add(new XYZConverter());
- jsetting.Converters.Add(new StringEnumConverter());
- jsetting.Converters.Add(new ParameterConverter());
- 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(dic, jsetting);
- return dataStr;
- }
- }
- }
|