C#开发BIMFACE系列17 服务端API之获取模型数据2:获取构件材质列表

时间:2023-03-08 16:34:41

在上一篇《C#开发BIMFACE系列16 服务端API之获取模型数据1:查询满足条件的构件ID列表》中介绍了获取单文件(模型)的所有构建ID列表。每个构建由多种材质组成,本文介绍获取单个构建ID的材质列表。

请求地址:GET https://api.bimface.com/data/v2/files/{fileId}/elements/{elementId}/materials

说明:根据单个构建ID获取其所有材质

参数:

C#开发BIMFACE系列17 服务端API之获取模型数据2:获取构件材质列表

请求 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" : "",
"name" : "METAL_(229,80,30)Steel",
"parameters" : [ {
"group" : "dimension",
"items" : [ {
"code" : "perimeter",
"extension" : "object",
"key" : "perimeter",
"orderNumber" : ,
"unit" : "mm",
"value" : ,
"valueType" :
} ]
} ]
} ],
"message" : ""
}

该响应结果的结构比较复杂,封装成C#实体类 SingleModelSingleElementMaterials 如下:

 /// <summary>
/// 获取单个模型单个构件的材质列表返回的结果类
/// </summary>
public class SingleModelSingleElementMaterials : GeneralResponse<List<MaterialInfo>>
{ }
 public class MaterialInfo
{
[JsonProperty("id")]
public string Id { get; set; } [JsonProperty("name")]
public string Name { get; set; } [JsonProperty("parameters")]
public PropertyGroup[] Parameters { get; set; } /// <summary>返回表示当前对象的字符串。</summary>
/// <returns>表示当前对象的字符串。</returns>
public override string ToString()
{
StringBuilder sb = new StringBuilder();
if (Parameters != null && Parameters.Length > )
{
foreach (var param in Parameters)
{
sb.AppendLine(param.ToString());
}
} return string.Format("[id={0}, name={1}, parameters={2}]",
Id, Name, sb);
}
}
 public class PropertyGroup
{
[JsonProperty("group")]
public string Group { get; set; } [JsonProperty("items")]
public PropertyItem[] Items { get; set; } /// <summary>返回表示当前对象的字符串。</summary>
/// <returns>表示当前对象的字符串。</returns>
public override string ToString()
{
StringBuilder sb = new StringBuilder();
if (Items != null && Items.Length > )
{
foreach (var item in Items)
{
sb.AppendLine(item.ToString());
}
} return string.Format("[group={0}, items={1}]",
Group, sb);
}
}
 public class PropertyItem
{
[JsonProperty("code")]
public string Code { get; set; } [JsonProperty("extension")]
public object Extension { get; set; } [JsonProperty("key")]
public string Key { get; set; } [JsonProperty("orderNumber")]
public int? OrderNumber { get; set; } [JsonProperty("unit")]
public string Unit { get; set; } [JsonProperty("value")]
public object Value { get; set; } [JsonProperty("valueType")]
public int? ValueType { get; set; } /// <summary>返回表示当前对象的字符串。</summary>
/// <returns>表示当前对象的字符串。</returns>
public override string ToString()
{
return string.Format("[code={0}, extension={1}, key={2}, orderNumber={3},unit={4},value={5},valueType={6}]",
Code, Extension, Key, OrderNumber, Unit, Value, ValueType);
}
}

C#实现方法:

 /// <summary>
/// 获取构件材质列表
/// </summary>
/// <param name="accessToken">令牌</param>
/// <param name="fileId">【必填】代表该单模型的文件ID</param>
/// <param name="elementId">【必填】代表该单模型的构件ID</param>
/// <returns></returns>
public virtual SingleModelSingleElementMaterials GetSingleModelSingleElementMaterials(string accessToken, long fileId,string elementId)
{
// GET https://api.bimface.com/data/v2/files/{fileId}/elements/{elementId}/materials
string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/elements/{1}/materials", fileId, elementId); BimFaceHttpHeaders headers = new BimFaceHttpHeaders();
headers.AddOAuth2Header(accessToken); try
{
SingleModelSingleElementMaterials response; HttpManager httpManager = new HttpManager(headers);
HttpResult httpResult = httpManager.Get(url);
if (httpResult.Status == HttpResult.STATUS_SUCCESS)
{
response = httpResult.Text.DeserializeJsonToObject<SingleModelSingleElementMaterials>();
}
else
{
response = new SingleModelSingleElementMaterials
{
Message = httpResult.RefText
};
} return response;
}
catch (Exception ex)
{
throw new Exception("[获取构件材质列表]发生异常!", ex);
}
}

其中调用到的 httpManager.Get() 方法,请参考《C# HTTP系列》

测试

在BIMFACE的控制台中可以看到我们上传的文件列表,共计2个文件。模型状态均为转换成功。

C#开发BIMFACE系列17 服务端API之获取模型数据2:获取构件材质列表

以“01_BIMFACE示例文件-Revit模型.rvt”为例来测试。

C#开发BIMFACE系列17 服务端API之获取模型数据2:获取构件材质列表

完整的材质列表为:

[id=, name=金属 - 铝, parameters=[group=标识数据, items=[code=, extension=, key=型号, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=成本, orderNumber=,unit=,value=0.00,valueType=]
[code=, extension=, key=URL, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=图像, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=注释, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=注释记号, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=标记, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=制造商, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=说明, orderNumber=,unit=,value=,valueType=]
]
[group=材质和装饰, items=[code=, extension=, key=名称, orderNumber=,unit=,value=金属 - 铝,valueType=]
[code=, extension=, key=高光, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=辉光, orderNumber=,unit=,value=False,valueType=]
[code=, extension=, key=平滑度, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=透明度, orderNumber=,unit=,value=,valueType=]
]
]

更换其他的构建ID,再次查询

C#开发BIMFACE系列17 服务端API之获取模型数据2:获取构件材质列表

完整的材质列表为:

[id=, name=混凝土砌块, parameters=[group=标识数据, items=[code=, extension=, key=型号, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=成本, orderNumber=,unit=,value=0.00,valueType=]
[code=, extension=, key=URL, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=图像, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=注释, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=注释记号, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=标记, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=制造商, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=说明, orderNumber=,unit=,value=混凝土砌块,valueType=]
]
[group=材质和装饰, items=[code=, extension=, key=剪变模量 X, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=子类, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=名称, orderNumber=,unit=,value=混凝土砌块,valueType=]
[code=, extension=, key=抗压强度, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=弹性模量 Y, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=类别, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=剪变模量 Z, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=弹性模量 Z, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=轻质, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=剪变模量 Y, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=抗剪强度折减系数, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=热膨胀系数 X, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=热膨胀系数 Y, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=热膨胀系数 Z, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=高光, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=辉光, orderNumber=,unit=,value=False,valueType=]
[code=, extension=, key=弹性模量 X, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=平滑度, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=表现, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=材质类型, orderNumber=,unit=,value=混凝土,valueType=]
[code=, extension=, key=透明度, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=泊松比 Z, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=泊松比 Y, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=泊松比 X, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=容重, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=阻尼比, orderNumber=,unit=,value=,valueType=]
]
],[id=, name=松散-石膏板, parameters=[group=标识数据, items=[code=, extension=, key=型号, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=成本, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=URL, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=图像, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=注释, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=注释记号, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=标记, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=制造商, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=说明, orderNumber=,unit=,value=内部面层,valueType=]
]
[group=材质和装饰, items=[code=, extension=, key=名称, orderNumber=,unit=,value=松散-石膏板,valueType=]
[code=, extension=, key=高光, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=辉光, orderNumber=,unit=,value=False,valueType=]
[code=, extension=, key=平滑度, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=透明度, orderNumber=,unit=,value=,valueType=]
]
],[id=, name=水泥砂浆, parameters=[group=标识数据, items=[code=, extension=, key=型号, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=成本, orderNumber=,unit=,value=0.00,valueType=]
[code=, extension=, key=URL, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=图像, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=注释, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=注释记号, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=标记, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=制造商, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=说明, orderNumber=,unit=,value=,valueType=]
]
[group=材质和装饰, items=[code=, extension=, key=名称, orderNumber=,unit=,value=水泥砂浆,valueType=]
[code=, extension=, key=高光, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=辉光, orderNumber=,unit=,value=False,valueType=]
[code=, extension=, key=平滑度, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=透明度, orderNumber=,unit=,value=,valueType=]
]
]

可以看到不同的构建ID,其组成材质不同。

测试代码如下:
 // 获取构件材质列表
protected void btnGetSingleModelSingleElementMaterials_Click(object sender, EventArgs e)
{
FileConvertApi api = new FileConvertApi(); string elementId = ddlSingleModelElements.SelectedValue; SingleModelSingleElementMaterials response = api.GetSingleModelSingleElementMaterials(txtAccessToken.Text, txtFileID.Text.ToLong(), elementId); txtResult.Text = response.Code.ToString2()
+ Environment.NewLine
+ "elementId:" + elementId
+ Environment.NewLine
+ response.Message.ToString2()
+ Environment.NewLine
+ response.Data.ToStringWith(",");
}