【已更新最新开发文章,点击查看详细】
BIMFACE平台提供了服务端“获取模型对比构件分类树”API。目录树返回结果以树状层级关系显示了增删改的构件信息,里面无法区分哪些构建是新增、修改或者删除的,所以在实际项目中使用意义不大。
请求地址:GET https://api.bimface.com/data/v2/comparisons/{comparisonId}/tree
参数:
请求 path(示例):https://api.bimface.com/data/v2/comparisons/1136906400211168/tree
请求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"
HTTP响应示例(200):
1 { 2 "code" : "success", 3 "data" : { 4 "items" : [ { 5 "actualName" : "actualName", 6 "data" : "object", 7 "elementCount" : 0, 8 "id" : "24507acf86734fcdafcfcc5b70497cd5", 9 "items" : [ { 10 "actualName" : "actualName", 11 "data" : "object", 12 "elementCount" : 0, 13 "id" : "24507acf86734fcdafcfcc5b70497cd5", 14 "items" : [ "..." ], 15 "name" : "name", 16 "type" : "type" 17 } ], 18 "name" : "name", 19 "type" : "type" 20 } ], 21 "root" : "specialty" 22 }, 23 "message" : "" 24 }
C#实现方法:
1 /// <summary> 2 /// 获取模型对比构件分类树 3 /// </summary> 4 /// <param name="accessToken">【必填】令牌</param> 5 /// <param name="compareId">【必填】对比ID</param> 6 /// <returns></returns> 7 public virtual ModelCompareTreeResponse GetModelCompareTree(string accessToken, long compareId) 8 { 9 // GET https://api.bimface.com/data/v2/comparisons/{comparisonId}/tree 10 string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/comparisons/{0}/tree", compareId); 11 12 BimFaceHttpHeaders headers = new BimFaceHttpHeaders(); 13 headers.AddOAuth2Header(accessToken); 14 15 try 16 { 17 ModelCompareTreeResponse response; 18 19 HttpManager httpManager = new HttpManager(headers); 20 HttpResult httpResult = httpManager.Get(url); 21 if (httpResult.Status == HttpResult.STATUS_SUCCESS) 22 { 23 response = httpResult.Text.DeserializeJsonToObject<ModelCompareTreeResponse>(); 24 } 25 else 26 { 27 response = new ModelCompareTreeResponse 28 { 29 Message = httpResult.RefText 30 }; 31 } 32 33 return response; 34 } 35 catch (Exception ex) 36 { 37 throw new Exception("[获取模型构件对比差异]发生异常!", ex); 38 } 39 }
代码中使用的 HttpManager 类请参考我的博客文章《C# HTTP系列 HttpWebRequest 与 HttpWebResponse》。
返回类型 ModelCompareTreeResponse 类如下:
1 /// <summary> 2 /// 获取模型构件对比差异的响应类 3 /// </summary> 4 public class ModelCompareTreeResponse : GeneralResponse<Tree> 5 { 6 } 7 8 public class Tree 9 { 10 [JsonProperty("items", NullValueHandling = NullValueHandling.Ignore)] 11 public TreeNode[] Items { get; set; } 12 13 [JsonProperty("root", NullValueHandling = NullValueHandling.Ignore)] 14 public string Root { get; set; } 15 } 16 17 public class TreeNode 18 { 19 [JsonProperty("actualName", NullValueHandling = NullValueHandling.Ignore)] 20 public string ActualName { get; set; } 21 22 [JsonProperty("data", NullValueHandling = NullValueHandling.Ignore)] 23 public object Data { get; set; } 24 25 [JsonProperty("elementCount", NullValueHandling = NullValueHandling.Ignore)] 26 public int? ElementCount { get; set; } 27 28 [JsonProperty("id", NullValueHandling = NullValueHandling.Ignore)] 29 public string Id { get; set; } 30 31 [JsonProperty("items", NullValueHandling = NullValueHandling.Ignore)] 32 public TreeNode[] Items { get; set; } 33 34 [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] 35 public string Name { get; set; } 36 37 [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] 38 public string Type { get; set; } 39 }