C#開發BIMFACE系列20 服務端API之獲取模型數據5:批量獲取構件屬性

在《C#開發BIMFACE系列18 服務端API之獲取模型數據3:獲取構件屬性》中介紹了獲取單個文件/模型的單個構建的屬性,本篇介紹如何一次性獲取多個構建的屬性。html

請求地址:POST https://api.bimface.com/data/v2/files/{fileId}/elementsapi

說明:支持查詢模型屬性重寫後多個構件的屬性,須要設置請求參數includeOverrides的值爲true數組

參數:
ide

 其中 ElementPropertyFilterRequest 類以下:測試

/// <summary>
///   批量獲取構件屬性的請求參數
/// </summary>
[Serializable]
public class ElementPropertyFilterRequest
{
    /// <summary>
    ///  【必填】構建ID數組。例如: [ "313154", "313047" ]
    /// </summary>
    [JsonProperty("elementIds")]
    public string[] ElementIds { get; set; }

    /// <summary>
    /// 【非必填】過來條件
    /// </summary>
    [JsonProperty("filter", NullValueHandling = NullValueHandling.Ignore)]
    public GroupAndKeysPair[] Filters { get; set; }
}
[Serializable]
public class GroupAndKeysPair
{
    /// <summary>
    ///  分組名稱。例如:default、shape、size
    /// </summary>
    [JsonProperty("group")]
    public string Group { get; set; }

    /// <summary>
    ///  關鍵字數組。例如: [ "length", "width", "a" ]
    /// </summary>
    [JsonProperty("keys", NullValueHandling = NullValueHandling.Ignore)]
    public string[] Keys { get; set; }
}

請求 path(示例):https://api.bimface.com/data/v2/files/1211223382064960/elementsui

若需查詢重寫後的構件屬性,請求示例爲url

https://api.bimface.com/data/v2/files/1211223382064960/elements?includeOverrides=truespa

請求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"code

請求 body(示例):orm

{
  "elementIds" : [ "313154", "313047" ],
  "filter" : [ {
    "group" : "default"
  }, {
    "group" : "shape"
  }, {
    "group" : "size",
    "keys" : [ "length", "width", "a" ]
  } ]
}

HTTP響應示例(200):

{
  "code" : "success",
  "data" : [ {
    "boundingBox" : {
      "max" : {
        "x" : -4938.068482562385,
        "y" : -3201.59397858169,
        "z" : 0.0
      },
      "min" : {
        "x" : -4938.068482562385,
        "y" : -3201.59397858169,
        "z" : 0.0
      }
    },
    "elementId" : "313052",
    "familyGuid" : "000222",
    "guid" : "79d547c1-5dbf-4e6a-811d-951cf37b29da-0004c6dc",
    "name" : "norm - 150mm",
    "properties" : [ {
      "group" : "dimension",
      "items" : [ {
        "code" : "perimeter",
        "extension" : "object",
        "key" : "perimeter",
        "orderNumber" : 0,
        "unit" : "mm",
        "value" : 17200,
        "valueType" : 2
      } ]
    } ]
  } ],
  "message" : ""
}

該返回結果中的data部分是一個數組,對應多個構建的屬性。與《C#開發BIMFACE系列18 服務端API之獲取模型數據3:獲取構件屬性》中返回的結果相同。

C#實現方法:

 1 /// <summary>
 2 ///  批量獲取單個模型的多個構件屬性
 3 /// </summary>
 4 /// <param name="accessToken">令牌</param>
 5 /// <param name="fileId">【必填】表明該單模型的文件ID</param>
 6 /// <param name="request">【必填】請求過濾參數</param>
 7 /// <param name="includeOverrides">【非必填】是否查詢修改的屬性</param>
 8 /// <returns></returns>
 9 public virtual SingleModelMultipleElementsProperties GetSingleModelMultipleElementsProperties(string accessToken, long fileId, ElementPropertyFilterRequest request, bool? includeOverrides = null)
10 {
11     if (request == null)
12     {
13         throw new ArgumentException("參數 request 不能爲null !");
14     }
15 
16     // POST https://api.bimface.com/data/v2/files/{fileId}/elements
17     string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/elements", fileId);
18     if (includeOverrides != null)
19     {
20         url = url + "?includeOverrides=" + includeOverrides;
21     }
22 
23     string data = request.SerializeToJson();
24 
25     BimFaceHttpHeaders headers = new BimFaceHttpHeaders();
26     headers.AddOAuth2Header(accessToken);
27 
28     try
29     {
30         SingleModelMultipleElementsProperties response;
31 
32         HttpManager httpManager = new HttpManager(headers);
33         HttpResult httpResult = httpManager.Post(url, data);
34         if (httpResult.Status == HttpResult.STATUS_SUCCESS)
35         {
36             response = httpResult.Text.DeserializeJsonToObject<SingleModelMultipleElementsProperties>();
37         }
38         else
39         {
40             response = new SingleModelMultipleElementsProperties
41             {
42                 Message = httpResult.RefText
43             };
44         }
45 
46         return response;
47     }
48     catch (Exception ex)
49     {
50         throw new Exception("[批量獲取構件屬性]發生異常!", ex);
51     }
52 }

其中調用到的 httpManager.Post() 方法,請參考《C# HTTP系列》

 其中返回結果類  SingleModelMultipleElementsProperties 定義以下:

/// <summary>
/// 批量獲取單個模型的多個構件屬性返回的結果類
/// </summary>
[Serializable]
public class SingleModelMultipleElementsProperties : GeneralResponse<List<SingleModelSingleElementEntity>>
{

}
測試

在BIMFACE的控制檯中能夠看到咱們上傳的文件列表,共計2個文件。模型狀態均爲轉換成功。

以「01_BIMFACE示例文件-Revit模型.rvt」爲例來測試。

其中使用了 300067,282979 這2個構建ID。查詢的構建屬性完整結果以下:

success
elementId:300067,282979

SingleModelSingleElementEntity: 
[boundingBox=[max=[x=5838.783, y=4387.716, z=6000], 
              min=[x=5788.783, y=4237.716, z=5475]
             ], 
 elementId=300067, 
 familyGuid=2d99307a-66cd-4439-b173-5c88d252416e-00002122, 
 Guid=89c90034-40ae-423a-8935-8f5624db86c1-00049423, 
 name=50 x 150 mm, 
 Properties=[group=基本屬性, 
             items= [code=, extension=, key=specialty, orderNumber=,unit=,value=,valueType=]
                    [code=, extension=, key=floor, orderNumber=,unit=,value=F2,valueType=]
                    [code=, extension=, key=categoryId, orderNumber=,unit=,value=-2000171,valueType=]
                    [code=, extension=, key=categoryName, orderNumber=,unit=,value=幕牆豎梃,valueType=]
                    [code=, extension=, key=family, orderNumber=,unit=,value=矩形豎梃,valueType=]
                    [code=, extension=, key=familyId, orderNumber=,unit=,value=,valueType=]
                    [code=, extension=, key=familyType, orderNumber=,unit=,value=50 x 150 mm,valueType=]
                    [code=, extension=, key=familyTypeId, orderNumber=,unit=,value=8486,valueType=]
                    [code=, extension=, key=systemType, orderNumber=,unit=,value=,valueType=]
                    [code=, extension=, key=building, orderNumber=,unit=,value=,valueType=]
            ]
            [group=尺寸標註, 
             items=[code=, extension=, key=邊 1 上的寬度, orderNumber=,unit=mm,value=25,valueType=2]
                   [code=, extension=, key=邊 2 上的寬度, orderNumber=,unit=mm,value=25,valueType=2]
                   [code=, extension=, key=長度, orderNumber=,unit=mm,value=525,valueType=2]
            ]
            [group=材質和裝飾, 
             items=[code=, extension=, key=材質, orderNumber=,unit=,value=金屬 - 鋁,valueType=4]
            ]
            [group=構造, 
             items=[code=, extension=, key=位置, orderNumber=,unit=,value=垂直於面,valueType=4]
                   [code=, extension=, key=厚度, orderNumber=,unit=mm,value=150,valueType=2]
                   [code=, extension=, key=角豎梃, orderNumber=,unit=,value=False,valueType=1]
                   [code=, extension=, key=輪廓, orderNumber=,unit=,value=默認,valueType=4]
            ]
            [group=標識數據, 
             items=[code=, extension=, key=OmniClass 標題, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=OmniClass 編號, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=URL, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=代碼名稱, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=製造商, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=圖像, orderNumber=,unit=,value=,valueType=4]
                    [code=, extension=, key=型號, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=成本, orderNumber=,unit=,value=,valueType=2]
                    [code=, extension=, key=標記, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=註釋, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=註釋記號, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=類型圖像, orderNumber=,unit=,value=,valueType=4]
                    [code=, extension=, key=類型標記, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=類型註釋, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=說明, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=部件代碼, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=部件說明, orderNumber=,unit=,value=,valueType=3]
            ]
            [group=階段化, 
             items=[code=, extension=, key=建立的階段, orderNumber=,unit=,value=新構造,valueType=4]
                   [code=, extension=, key=拆除的階段, orderNumber=,unit=,value=無,valueType=4]
            ]
            [group=限制條件, 
             items=[code=, extension=, key=偏移量, orderNumber=,unit=mm,value=0,valueType=2]
                   [code=, extension=, key=角度, orderNumber=,unit=°,value=0.00,valueType=2]
            ]
]

SingleModelSingleElementEntity: 
[boundingBox=[max=[x=-2066.217, y=-7714.284, z=3175], 
              min=[x=-2116.217, y=-7864.284, z=2750]
             ], 
 elementId=282979, 
 familyGuid=2d99307a-66cd-4439-b173-5c88d252416e-00002122, 
 Guid=0438595c-b6fe-4e10-9b43-4c629826282c-00045163, 
 name=50 x 150 mm, 
 Properties=[group=基本屬性, 
             items=[code=, extension=, key=specialty, orderNumber=,unit=,value=,valueType=]
                    [code=, extension=, key=floor, orderNumber=,unit=,value=地坪,valueType=]
                    [code=, extension=, key=categoryId, orderNumber=,unit=,value=-2000171,valueType=]
                    [code=, extension=, key=categoryName, orderNumber=,unit=,value=幕牆豎梃,valueType=]
                    [code=, extension=, key=family, orderNumber=,unit=,value=矩形豎梃,valueType=]
                    [code=, extension=, key=familyId, orderNumber=,unit=,value=,valueType=]
                    [code=, extension=, key=familyType, orderNumber=,unit=,value=50 x 150 mm,valueType=]
                    [code=, extension=, key=familyTypeId, orderNumber=,unit=,value=8486,valueType=]
                    [code=, extension=, key=systemType, orderNumber=,unit=,value=,valueType=]
                    [code=, extension=, key=building, orderNumber=,unit=,value=,valueType=]
            ]
            [group=尺寸標註, 
             items=[code=, extension=, key=邊 1 上的寬度, orderNumber=,unit=mm,value=25,valueType=2]
                    [code=, extension=, key=邊 2 上的寬度, orderNumber=,unit=mm,value=25,valueType=2]
                    [code=, extension=, key=長度, orderNumber=,unit=mm,value=425,valueType=2]
            ]
            [group=材質和裝飾, 
             items=[code=, extension=, key=材質, orderNumber=,unit=,value=金屬 - 鋁,valueType=4]
            ]
            [group=構造, 
             items=[code=, extension=, key=位置, orderNumber=,unit=,value=垂直於面,valueType=4]
                    [code=, extension=, key=厚度, orderNumber=,unit=mm,value=150,valueType=2]
                    [code=, extension=, key=角豎梃, orderNumber=,unit=,value=False,valueType=1]
                    [code=, extension=, key=輪廓, orderNumber=,unit=,value=默認,valueType=4]
            ]
            [group=標識數據, 
             items=[code=, extension=, key=OmniClass 標題, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=OmniClass 編號, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=URL, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=代碼名稱, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=製造商, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=圖像, orderNumber=,unit=,value=,valueType=4]
                    [code=, extension=, key=型號, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=成本, orderNumber=,unit=,value=,valueType=2]
                    [code=, extension=, key=標記, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=註釋, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=註釋記號, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=類型圖像, orderNumber=,unit=,value=,valueType=4]
                    [code=, extension=, key=類型標記, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=類型註釋, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=說明, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=部件代碼, orderNumber=,unit=,value=,valueType=3]
                    [code=, extension=, key=部件說明, orderNumber=,unit=,value=,valueType=3]
            ]
            [group=階段化, 
             items=[code=, extension=, key=建立的階段, orderNumber=,unit=,value=新構造,valueType=4]
                   [code=, extension=, key=拆除的階段, orderNumber=,unit=,value=無,valueType=4]
            ]
            [group=限制條件, 
             items=[code=, extension=, key=偏移量, orderNumber=,unit=mm,value=0,valueType=2]
                   [code=, extension=, key=角度, orderNumber=,unit=°,value=0.00,valueType=2]
            ]
]

測試代碼以下:

 1 // 批量獲取構件屬性
 2 protected void btnGetSingleModelMultipleElementsProperties_Click(object sender, EventArgs e)
 3 {
 4     string[] elementIds = txtMultipleElementIds.Text.Split(",");
 5 
 6     ElementPropertyFilterRequest request = new ElementPropertyFilterRequest();
 7     request.ElementIds = elementIds;
 8 
 9     FileConvertApi api = new FileConvertApi();
10     var response = api.GetSingleModelMultipleElementsProperties(txtAccessToken.Text, txtFileID.Text.ToLong(), request, chkIncludeOverrides.Checked);
11 
12     StringBuilder sb = new StringBuilder();
13     List<SingleModelSingleElementEntity> lstProperties = response.Data;
14     foreach (var property in lstProperties)
15     {
16         sb.AppendLine(property.ToString());
17     }
18     txtResult.Text = response.Code.ToString2()
19                    + Environment.NewLine
20                    + "elementId:" + txtMultipleElementIds.Text
21                    + Environment.NewLine
22                    + response.Message.ToString2()
23                    + Environment.NewLine
24                    + sb;
25 }

 

相關文章
相關標籤/搜索