在上一篇《C#開發BIMFACE系列16 服務端API之獲取模型數據1:查詢知足條件的構件ID列表》中介紹了獲取單文件(模型)的全部構建ID列表。每一個構建由多種材質組成,本文介紹獲取單個構建ID的材質列表。html
請求地址:GET https://api.bimface.com/data/v2/files/{fileId}/elements/{elementId}/materialsapi
說明:根據單個構建ID獲取其全部材質
ide
參數:測試
請求 path(示例):https://api.bimface.com/data/v2/files/1211223382064960/elements/618987/materialsui
請求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"url
HTTP響應示例(200):spa
{ "code" : "success", "data" : [ { "id" : "2856106", "name" : "METAL_(229,80,30)Steel", "parameters" : [ { "group" : "dimension", "items" : [ { "code" : "perimeter", "extension" : "object", "key" : "perimeter", "orderNumber" : 0, "unit" : "mm", "value" : 17200, "valueType" : 2 } ] } ] } ], "message" : "" }
該響應結果的結構比較複雜,封裝成C#實體類 SingleModelSingleElementMaterials 以下:code
1 /// <summary> 2 /// 獲取單個模型單個構件的材質列表返回的結果類 3 /// </summary> 4 public class SingleModelSingleElementMaterials : GeneralResponse<List<MaterialInfo>> 5 { 6 7 }
1 public class MaterialInfo 2 { 3 [JsonProperty("id")] 4 public string Id { get; set; } 5 6 [JsonProperty("name")] 7 public string Name { get; set; } 8 9 [JsonProperty("parameters")] 10 public PropertyGroup[] Parameters { get; set; } 11 12 /// <summary>返回表示當前對象的字符串。</summary> 13 /// <returns>表示當前對象的字符串。</returns> 14 public override string ToString() 15 { 16 StringBuilder sb = new StringBuilder(); 17 if (Parameters != null && Parameters.Length > 0) 18 { 19 foreach (var param in Parameters) 20 { 21 sb.AppendLine(param.ToString()); 22 } 23 } 24 25 return string.Format("[id={0}, name={1}, parameters={2}]", 26 Id, Name, sb); 27 } 28 }
1 public class PropertyGroup 2 { 3 [JsonProperty("group")] 4 public string Group { get; set; } 5 6 [JsonProperty("items")] 7 public PropertyItem[] Items { get; set; } 8 9 /// <summary>返回表示當前對象的字符串。</summary> 10 /// <returns>表示當前對象的字符串。</returns> 11 public override string ToString() 12 { 13 StringBuilder sb = new StringBuilder(); 14 if (Items != null && Items.Length > 0) 15 { 16 foreach (var item in Items) 17 { 18 sb.AppendLine(item.ToString()); 19 } 20 } 21 22 return string.Format("[group={0}, items={1}]", 23 Group, sb); 24 } 25 }
1 public class PropertyItem 2 { 3 [JsonProperty("code")] 4 public string Code { get; set; } 5 6 [JsonProperty("extension")] 7 public object Extension { get; set; } 8 9 [JsonProperty("key")] 10 public string Key { get; set; } 11 12 [JsonProperty("orderNumber")] 13 public int? OrderNumber { get; set; } 14 15 [JsonProperty("unit")] 16 public string Unit { get; set; } 17 18 [JsonProperty("value")] 19 public object Value { get; set; } 20 21 [JsonProperty("valueType")] 22 public int? ValueType { get; set; } 23 24 /// <summary>返回表示當前對象的字符串。</summary> 25 /// <returns>表示當前對象的字符串。</returns> 26 public override string ToString() 27 { 28 return string.Format("[code={0}, extension={1}, key={2}, orderNumber={3},unit={4},value={5},valueType={6}]", 29 Code, Extension, Key, OrderNumber, Unit, Value, ValueType); 30 } 31 }
C#實現方法:orm
1 /// <summary> 2 /// 獲取構件材質列表 3 /// </summary> 4 /// <param name="accessToken">令牌</param> 5 /// <param name="fileId">【必填】表明該單模型的文件ID</param> 6 /// <param name="elementId">【必填】表明該單模型的構件ID</param> 7 /// <returns></returns> 8 public virtual SingleModelSingleElementMaterials GetSingleModelSingleElementMaterials(string accessToken, long fileId,string elementId) 9 { 10 // GET https://api.bimface.com/data/v2/files/{fileId}/elements/{elementId}/materials 11 string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/elements/{1}/materials", fileId, elementId); 12 13 BimFaceHttpHeaders headers = new BimFaceHttpHeaders(); 14 headers.AddOAuth2Header(accessToken); 15 16 try 17 { 18 SingleModelSingleElementMaterials response; 19 20 HttpManager httpManager = new HttpManager(headers); 21 HttpResult httpResult = httpManager.Get(url); 22 if (httpResult.Status == HttpResult.STATUS_SUCCESS) 23 { 24 response = httpResult.Text.DeserializeJsonToObject<SingleModelSingleElementMaterials>(); 25 } 26 else 27 { 28 response = new SingleModelSingleElementMaterials 29 { 30 Message = httpResult.RefText 31 }; 32 } 33 34 return response; 35 } 36 catch (Exception ex) 37 { 38 throw new Exception("[獲取構件材質列表]發生異常!", ex); 39 } 40 }
其中調用到的 httpManager.Get() 方法,請參考《C# HTTP系列》htm
在BIMFACE的控制檯中能夠看到咱們上傳的文件列表,共計2個文件。模型狀態均爲轉換成功。
以「01_BIMFACE示例文件-Revit模型.rvt」爲例來測試。
完整的材質列表爲:
[id=268711, name=金屬 - 鋁, parameters=[group=標識數據, items=[code=, extension=, key=型號, orderNumber=,unit=,value=,valueType=3] [code=, extension=, key=成本, orderNumber=,unit=,value=0.00,valueType=2] [code=, extension=, key=URL, 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=3] [code=, extension=, key=高光, orderNumber=,unit=,value=128,valueType=1] [code=, extension=, key=輝光, orderNumber=,unit=,value=False,valueType=1] [code=, extension=, key=平滑度, orderNumber=,unit=,value=50,valueType=1] [code=, extension=, key=透明度, orderNumber=,unit=,value=0,valueType=1] ] ]
更換其餘的構建ID,再次查詢
完整的材質列表爲:
[id=415, name=混凝土砌塊, parameters=[group=標識數據, items=[code=, extension=, key=型號, orderNumber=,unit=,value=,valueType=3] [code=, extension=, key=成本, orderNumber=,unit=,value=0.00,valueType=2] [code=, extension=, key=URL, 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=剪變模量 X, 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=2] [code=, extension=, key=彈性模量 Y, orderNumber=,unit=,value=,valueType=2] [code=, extension=, key=類別, orderNumber=,unit=,value=,valueType=1] [code=, extension=, key=剪變模量 Z, orderNumber=,unit=,value=,valueType=2] [code=, extension=, key=彈性模量 Z, orderNumber=,unit=,value=,valueType=2] [code=, extension=, key=輕質, orderNumber=,unit=,value=,valueType=1] [code=, extension=, key=剪變模量 Y, orderNumber=,unit=,value=,valueType=2] [code=, extension=, key=抗剪強度折減係數, orderNumber=,unit=,value=,valueType=2] [code=, extension=, key=熱膨脹係數 X, orderNumber=,unit=,value=,valueType=2] [code=, extension=, key=熱膨脹係數 Y, orderNumber=,unit=,value=,valueType=2] [code=, extension=, key=熱膨脹係數 Z, orderNumber=,unit=,value=,valueType=2] [code=, extension=, key=高光, orderNumber=,unit=,value=128,valueType=1] [code=, extension=, key=輝光, orderNumber=,unit=,value=False,valueType=1] [code=, extension=, key=彈性模量 X, orderNumber=,unit=,value=,valueType=2] [code=, extension=, key=平滑度, orderNumber=,unit=,value=50,valueType=1] [code=, extension=, key=表現, orderNumber=,unit=,value=,valueType=1] [code=, extension=, key=材質類型, orderNumber=,unit=,value=混凝土,valueType=1] [code=, extension=, key=透明度, orderNumber=,unit=,value=0,valueType=1] [code=, extension=, key=泊松比 Z, orderNumber=,unit=,value=,valueType=2] [code=, extension=, key=泊松比 Y, orderNumber=,unit=,value=,valueType=2] [code=, extension=, key=泊松比 X, orderNumber=,unit=,value=,valueType=2] [code=, extension=, key=容重, orderNumber=,unit=,value=,valueType=2] [code=, extension=, key=阻尼比, orderNumber=,unit=,value=,valueType=2] ] ],[id=423, name=鬆散-石膏板, parameters=[group=標識數據, items=[code=, extension=, key=型號, orderNumber=,unit=,value=,valueType=3] [code=, extension=, key=成本, orderNumber=,unit=,value=,valueType=2] [code=, extension=, key=URL, 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=3] [code=, extension=, key=高光, orderNumber=,unit=,value=128,valueType=1] [code=, extension=, key=輝光, orderNumber=,unit=,value=False,valueType=1] [code=, extension=, key=平滑度, orderNumber=,unit=,value=50,valueType=1] [code=, extension=, key=透明度, orderNumber=,unit=,value=0,valueType=1] ] ],[id=813, name=水泥砂漿, parameters=[group=標識數據, items=[code=, extension=, key=型號, orderNumber=,unit=,value=,valueType=3] [code=, extension=, key=成本, orderNumber=,unit=,value=0.00,valueType=2] [code=, extension=, key=URL, 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=3] [code=, extension=, key=高光, orderNumber=,unit=,value=0,valueType=1] [code=, extension=, key=輝光, orderNumber=,unit=,value=False,valueType=1] [code=, extension=, key=平滑度, orderNumber=,unit=,value=50,valueType=1] [code=, extension=, key=透明度, orderNumber=,unit=,value=0,valueType=1] ] ]
能夠看到不一樣的構建ID,其組成材質不一樣。
1 // 獲取構件材質列表 2 protected void btnGetSingleModelSingleElementMaterials_Click(object sender, EventArgs e) 3 { 4 FileConvertApi api = new FileConvertApi(); 5 6 string elementId = ddlSingleModelElements.SelectedValue; 7 8 SingleModelSingleElementMaterials response = api.GetSingleModelSingleElementMaterials(txtAccessToken.Text, txtFileID.Text.ToLong(), elementId); 9 10 txtResult.Text = response.Code.ToString2() 11 + Environment.NewLine 12 + "elementId:" + elementId 13 + Environment.NewLine 14 + response.Message.ToString2() 15 + Environment.NewLine 16 + response.Data.ToStringWith(","); 17 }