在上一篇《C#开发BIMFACE系列16 服务端API之获取模型数据1:查询满足条件的构件ID列表》中介绍了获取单文件(模型)的所有构建ID列表。每个构建由多种材质组成,本文介绍获取单个构建ID的材质列表。
请求地址:GET https://api.bimface.com/data/v2/files/{fileId}/elements/{elementId}/materials
说明:根据单个构建ID获取其所有材质
参数:
请求 path(示例):https://api.bimface.com/data/v2/files/1211223382064960/elements/618987/materials
请求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"
HTTP响应示例(200):
{ "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 如下:
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#实现方法:
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系列》
在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 }
文章来源: 博客园
- 还没有人评论,欢迎说说您的想法!