• C#开发BIMFACE系列35 服务端API之模型对比6:获取模型构建对比分类树


      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 }
    View Code
    测试

    测试代码:

     1 /// <summary>
     2 ///  获取模型对比构件分类树
     3 /// </summary>
     4 protected void btnGetModelCompareTree_Click(object sender, EventArgs e)
     5 {
     6     txtResult.Text = string.Empty;
     7 
     8     long compareId = txtCompareID.Text.ToLong();
     9     IModelCompareApi api = new ModelCompareApi();
    10     ModelCompareTreeResponse response = api.GetModelCompareTree(txtAccessToken.Text, compareId);
    11 
    12     txtResult.Text = response.SerializeToJson(true);
    13 }

    测试结果:

     完整结果为:

      1 {
      2   "code": "success",
      3   "message": null,
      4   "data": {
      5     "items": [
      6       {
      7         "actualName": "",
      8         "elementCount": 48,
      9         "id": "-2000011",
     10         "items": [
     11           {
     12             "actualName": "基本墙",
     13             "elementCount": 48,
     14             "items": [],
     15             "name": "基本墙",
     16             "type": "family"
     17           }
     18         ],
     19         "name": "",
     20         "type": "category"
     21       },
     22       {
     23         "actualName": "楼板",
     24         "elementCount": 2,
     25         "id": "-2000032",
     26         "items": [
     27           {
     28             "actualName": "楼板",
     29             "elementCount": 2,
     30             "items": [],
     31             "name": "楼板",
     32             "type": "family"
     33           }
     34         ],
     35         "name": "楼板",
     36         "type": "category"
     37       },
     38       {
     39         "actualName": "家具",
     40         "elementCount": 30,
     41         "id": "-2000080",
     42         "items": [
     43           {
     44             "actualName": "Bar Chair",
     45             "elementCount": 6,
     46             "items": [],
     47             "name": "Bar Chair",
     48             "type": "family"
     49           },
     50           {
     51             "actualName": "Cabinet 1",
     52             "elementCount": 1,
     53             "items": [],
     54             "name": "Cabinet 1",
     55             "type": "family"
     56           },
     57           {
     58             "actualName": "Dining Chair (3)",
     59             "elementCount": 8,
     60             "items": [],
     61             "name": "Dining Chair (3)",
     62             "type": "family"
     63           },
     64           {
     65             "actualName": "M_TV - Flat Screen",
     66             "elementCount": 1,
     67             "items": [],
     68             "name": "M_TV - Flat Screen",
     69             "type": "family"
     70           },
     71           {
     72             "actualName": "Seat - Single with Island",
     73             "elementCount": 1,
     74             "items": [],
     75             "name": "Seat - Single with Island",
     76             "type": "family"
     77           },
     78           {
     79             "actualName": "Seating - Artemis - Lounge chair",
     80             "elementCount": 2,
     81             "items": [],
     82             "name": "Seating - Artemis - Lounge chair",
     83             "type": "family"
     84           },
     85           {
     86             "actualName": "Side Table 2 (2)",
     87             "elementCount": 2,
     88             "items": [],
     89             "name": "Side Table 2 (2)",
     90             "type": "family"
     91           },
     92           {
     93             "actualName": "Sofa - Ottoman",
     94             "elementCount": 7,
     95             "items": [],
     96             "name": "Sofa - Ottoman",
     97             "type": "family"
     98           },
     99           {
    100             "actualName": "Table-Dining 01 (M)",
    101             "elementCount": 2,
    102             "items": [],
    103             "name": "Table-Dining 01 (M)",
    104             "type": "family"
    105           }
    106         ],
    107         "name": "家具",
    108         "type": "category"
    109       },
    110       {
    111         "actualName": "楼梯",
    112         "elementCount": 3,
    113         "id": "-2000120",
    114         "items": [
    115           {
    116             "actualName": "组合楼梯",
    117             "elementCount": 1,
    118             "items": [],
    119             "name": "组合楼梯",
    120             "type": "family"
    121           },
    122           {
    123             "actualName": "预浇注楼梯",
    124             "elementCount": 2,
    125             "items": [],
    126             "name": "预浇注楼梯",
    127             "type": "family"
    128           }
    129         ],
    130         "name": "楼梯",
    131         "type": "category"
    132       },
    133       {
    134         "actualName": "栏杆扶手",
    135         "elementCount": 10,
    136         "id": "-2000126",
    137         "items": [
    138           {
    139             "actualName": "栏杆扶手",
    140             "elementCount": 10,
    141             "items": [],
    142             "name": "栏杆扶手",
    143             "type": "family"
    144           }
    145         ],
    146         "name": "栏杆扶手",
    147         "type": "category"
    148       },
    149       {
    150         "actualName": "常规模型",
    151         "elementCount": 26,
    152         "id": "-2000151",
    153         "items": [
    154           {
    155             "actualName": "Miele Built-under Dishwasher G 4101 U CS",
    156             "elementCount": 1,
    157             "items": [],
    158             "name": "Miele Built-under Dishwasher G 4101 U CS",
    159             "type": "family"
    160           },
    161           {
    162             "actualName": "Miele Induction Cooktop KM 6350 LPT",
    163             "elementCount": 1,
    164             "items": [],
    165             "name": "Miele Induction Cooktop KM 6350 LPT",
    166             "type": "family"
    167           },
    168           {
    169             "actualName": "Miele Washing Machine W 5820 WPS",
    170             "elementCount": 1,
    171             "items": [],
    172             "name": "Miele Washing Machine W 5820 WPS",
    173             "type": "family"
    174           },
    175           {
    176             "actualName": "Walvit_Hung Bowl_604118 W",
    177             "elementCount": 4,
    178             "items": [],
    179             "name": "Walvit_Hung Bowl_604118 W",
    180             "type": "family"
    181           },
    182           {
    183             "actualName": "Water Glass",
    184             "elementCount": 8,
    185             "items": [],
    186             "name": "Water Glass",
    187             "type": "family"
    188           },
    189           {
    190             "actualName": "White Porcelain Plate",
    191             "elementCount": 8,
    192             "items": [],
    193             "name": "White Porcelain Plate",
    194             "type": "family"
    195           },
    196           {
    197             "actualName": "aalto vase - tall",
    198             "elementCount": 1,
    199             "items": [],
    200             "name": "aalto vase - tall",
    201             "type": "family"
    202           },
    203           {
    204             "actualName": "fire place hang",
    205             "elementCount": 1,
    206             "items": [],
    207             "name": "fire place hang",
    208             "type": "family"
    209           },
    210           {
    211             "actualName": "宣传画",
    212             "elementCount": 1,
    213             "items": [],
    214             "name": "宣传画",
    215             "type": "family"
    216           }
    217         ],
    218         "name": "常规模型",
    219         "type": "category"
    220       },
    221       {
    222         "actualName": "橱柜",
    223         "elementCount": 2,
    224         "id": "-2001000",
    225         "items": [
    226           {
    227             "actualName": "4500_Kitchen Island",
    228             "elementCount": 1,
    229             "items": [],
    230             "name": "4500_Kitchen Island",
    231             "type": "family"
    232           },
    233           {
    234             "actualName": "4500_Kitchen Island_DW",
    235             "elementCount": 1,
    236             "items": [],
    237             "name": "4500_Kitchen Island_DW",
    238             "type": "family"
    239           }
    240         ],
    241         "name": "橱柜",
    242         "type": "category"
    243       },
    244       {
    245         "actualName": "电气设备",
    246         "elementCount": 12,
    247         "id": "-2001040",
    248         "items": [
    249           {
    250             "actualName": "Photovoltaic-Panel-SolarWorld-SunModule-(235-240)",
    251             "elementCount": 12,
    252             "items": [],
    253             "name": "Photovoltaic-Panel-SolarWorld-SunModule-(235-240)",
    254             "type": "family"
    255           }
    256         ],
    257         "name": "电气设备",
    258         "type": "category"
    259       },
    260       {
    261         "actualName": "照明设备",
    262         "elementCount": 8,
    263         "id": "-2001120",
    264         "items": [
    265           {
    266             "actualName": "Trck_BswySystms_Cooper_RSA_Profile Series_AR111 Closed Back Integral Xfmr",
    267             "elementCount": 8,
    268             "items": [],
    269             "name": "Trck_BswySystms_Cooper_RSA_Profile Series_AR111 Closed Back Integral Xfmr",
    270             "type": "family"
    271           }
    272         ],
    273         "name": "照明设备",
    274         "type": "category"
    275       },
    276       {
    277         "actualName": "卫浴装置",
    278         "elementCount": 6,
    279         "id": "-2001160",
    280         "items": [
    281           {
    282             "actualName": "DC_Tankworks_PLM_5000L",
    283             "elementCount": 2,
    284             "items": [],
    285             "name": "DC_Tankworks_PLM_5000L",
    286             "type": "family"
    287           },
    288           {
    289             "actualName": "Lavatory-TOTO-Luminist_Rectangle_Vessel_LLT151",
    290             "elementCount": 4,
    291             "items": [],
    292             "name": "Lavatory-TOTO-Luminist_Rectangle_Vessel_LLT151",
    293             "type": "family"
    294           }
    295         ],
    296         "name": "卫浴装置",
    297         "type": "category"
    298       },
    299       {
    300         "actualName": "场地",
    301         "elementCount": 3,
    302         "id": "-2001260",
    303         "items": [
    304           {
    305             "actualName": "M_Wind Power Generator",
    306             "elementCount": 3,
    307             "items": [],
    308             "name": "M_Wind Power Generator",
    309             "type": "family"
    310           }
    311         ],
    312         "name": "场地",
    313         "type": "category"
    314       },
    315       {
    316         "actualName": "建筑地坪",
    317         "elementCount": 1,
    318         "id": "-2001263",
    319         "items": [
    320           {
    321             "actualName": "建筑地坪",
    322             "elementCount": 1,
    323             "items": [],
    324             "name": "建筑地坪",
    325             "type": "family"
    326           }
    327         ],
    328         "name": "建筑地坪",
    329         "type": "category"
    330       },
    331       {
    332         "actualName": "结构基础",
    333         "elementCount": 22,
    334         "id": "-2001300",
    335         "items": [
    336           {
    337             "actualName": "M_Pile Cap-600 Pile",
    338             "elementCount": 11,
    339             "items": [],
    340             "name": "M_Pile Cap-600 Pile",
    341             "type": "family"
    342           },
    343           {
    344             "actualName": "M_Pile-Steel Pipe",
    345             "elementCount": 11,
    346             "items": [],
    347             "name": "M_Pile-Steel Pipe",
    348             "type": "family"
    349           }
    350         ],
    351         "name": "结构基础",
    352         "type": "category"
    353       },
    354       {
    355         "actualName": "结构柱",
    356         "elementCount": 1,
    357         "id": "-2001330",
    358         "items": [
    359           {
    360             "actualName": "M_Concrete-Round-Column with Drop Caps",
    361             "elementCount": 1,
    362             "items": [],
    363             "name": "M_Concrete-Round-Column with Drop Caps",
    364             "type": "family"
    365           }
    366         ],
    367         "name": "结构柱",
    368         "type": "category"
    369       },
    370       {
    371         "actualName": "专用设备",
    372         "elementCount": 7,
    373         "id": "-2001350",
    374         "items": [
    375           {
    376             "actualName": "Miele Built-in Microwave M 8260-2",
    377             "elementCount": 1,
    378             "items": [],
    379             "name": "Miele Built-in Microwave M 8260-2",
    380             "type": "family"
    381           },
    382           {
    383             "actualName": "Miele Built-in Rangehood DA 2210",
    384             "elementCount": 1,
    385             "items": [],
    386             "name": "Miele Built-in Rangehood DA 2210",
    387             "type": "family"
    388           },
    389           {
    390             "actualName": "Miele MasterCool KF 1911 Vi",
    391             "elementCount": 1,
    392             "items": [],
    393             "name": "Miele MasterCool KF 1911 Vi",
    394             "type": "family"
    395           },
    396           {
    397             "actualName": "Miele Oven H 5681 BP",
    398             "elementCount": 1,
    399             "items": [],
    400             "name": "Miele Oven H 5681 BP",
    401             "type": "family"
    402           },
    403           {
    404             "actualName": "Miele Tumble Dryer T 7944 C",
    405             "elementCount": 1,
    406             "items": [],
    407             "name": "Miele Tumble Dryer T 7944 C",
    408             "type": "family"
    409           },
    410           {
    411             "actualName": "Vase (3)-with Flower",
    412             "elementCount": 1,
    413             "items": [],
    414             "name": "Vase (3)-with Flower",
    415             "type": "family"
    416           },
    417           {
    418             "actualName": "Wine Bottles",
    419             "elementCount": 1,
    420             "items": [],
    421             "name": "Wine Bottles",
    422             "type": "family"
    423           }
    424         ],
    425         "name": "专用设备",
    426         "type": "category"
    427       },
    428       {
    429         "actualName": "植物",
    430         "elementCount": 16,
    431         "id": "-2001360",
    432         "items": [
    433           {
    434             "actualName": "RPC Tree - Deciduous",
    435             "elementCount": 16,
    436             "items": [],
    437             "name": "RPC Tree - Deciduous",
    438             "type": "family"
    439           }
    440         ],
    441         "name": "植物",
    442         "type": "category"
    443       },
    444       {
    445         "actualName": "环境",
    446         "elementCount": 5,
    447         "id": "-2001370",
    448         "items": [
    449           {
    450             "actualName": "M_RPC Beetle",
    451             "elementCount": 1,
    452             "items": [],
    453             "name": "M_RPC Beetle",
    454             "type": "family"
    455           },
    456           {
    457             "actualName": "RPC Female",
    458             "elementCount": 3,
    459             "items": [],
    460             "name": "RPC Female",
    461             "type": "family"
    462           },
    463           {
    464             "actualName": "RPC Male",
    465             "elementCount": 1,
    466             "items": [],
    467             "name": "RPC Male",
    468             "type": "family"
    469           }
    470         ],
    471         "name": "环境",
    472         "type": "category"
    473       }
    474     ],
    475     "root": "category"
    476   }
    477 }
    View Code
  • 相关阅读:
    前端开发——HTML学习笔记
    前端开发——HTML学习笔记
    前端开发——HTML学习笔记
    日记2018/1/4
    物联网概念
    安卓常见英文缩写的全拼
    快速排序和计数排序API
    Hash表API
    栈/队列API(push和pop)
    链表API实现(插入,删除,查找)
  • 原文地址:https://www.cnblogs.com/SavionZhang/p/12396032.html
Copyright © 2020-2023  润新知