C#开发BIMFACE系列19 服务端API之获取模型数据4:获取多个构件的共同属性

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

在前几篇博客中介绍了一个三维文件/模型包含多个构建,每个构建又是由多种材质组成,每个构建都有很多属性。不同的构建也有可能包含相同的属性。

C#开发BIMFACE系列19 服务端API之获取模型数据4:获取多个构件的共同属性

上图中可以看到构建1与构建2拥有相同的属性2,构建2与构建n拥有相同的属性1。

本文主要介绍如何获取多个构建的共同属性。

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

说明:若传入的elementId不止一个,则返回这些elementId共同的属性,共同的定义为:属性key与value都相等。

支持查询模型属性重写后多个构件的共同属性,需要设置请求参数includeOverrides的值为true。

参数:

C#开发BIMFACE系列19 服务端API之获取模型数据4:获取多个构件的共同属性

请求 path(示例):https://api.bimface.com/data/v2/files/1211223382064960/commonElementProperties?elementIds=string

若需查询重写后的构件的共同属性,请求示例为
  https://api.bimface.com/data/v2/files/1211223382064960/commonElementProperties?elementIds=string&includeOverrides=true

elementIds 后面的 string 是多个构建Id,多个elementId之间用英文状态下的半角逗号分隔。

例如:elementId1,elementId2,elementId3,elementId4

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

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" : "",
"familyGuid" : "",
"guid" : "79d547c1-5dbf-4e6a-811d-951cf37b29da-0004c6dc",
"name" : "norm - 150mm",
"properties" : [ {
"group" : "dimension",
"items" : [ {
"code" : "perimeter",
"extension" : "object",
"key" : "perimeter",
"orderNumber" : ,
"unit" : "mm",
"value" : ,
"valueType" :
} ]
} ]
},
"message" : ""
}

C#实现方法:

 /// <summary>
/// 获取单个模型的多个构件的共同属性
/// </summary>
/// <param name="accessToken">令牌</param>
/// <param name="fileId">【必填】代表该单模型的文件ID</param>
/// <param name="elementIds">【必填】代表该单模型的构件ID列表</param>
/// <param name="includeOverrides">【非必填】是否查询修改的属性</param>
/// <returns></returns>
public virtual SingleModelMultipleElementsCommonProperties GetSingleModelMultipleElementsCommonProperties(string accessToken, long fileId, string[] elementIds, bool? includeOverrides = null)
{
if (elementIds == null && elementIds.Length == )
{
throw new ArgumentException("参数 elementIds 不能为null 且必须包含元素!");
} // GET https://api.bimface.com/data/v2/files/{fileId}/commonElementProperties?elementIds={string}
string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/commonElementProperties?elementIds={1}", fileId, elementIds.ToStringWith(","));
if (includeOverrides != null)
{
url = url + "&includeOverrides=" + includeOverrides;
} BimFaceHttpHeaders headers = new BimFaceHttpHeaders();
headers.AddOAuth2Header(accessToken); try
{
SingleModelMultipleElementsCommonProperties response; HttpManager httpManager = new HttpManager(headers);
HttpResult httpResult = httpManager.Get(url);
if (httpResult.Status == HttpResult.STATUS_SUCCESS)
{
response = httpResult.Text.DeserializeJsonToObject<SingleModelMultipleElementsCommonProperties>();
}
else
{
response = new SingleModelMultipleElementsCommonProperties
{
Message = httpResult.RefText
};
} return response;
}
catch (Exception ex)
{
throw new Exception("[获取多个构件的共同属性]发生异常!", ex);
}
}

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

响应结果对应的实体类 SingleModelMultipleElementsCommonProperties ,封装如下:

/// <summary>
/// 获取多个构件的共同属性返回的结果类
/// </summary>
public class SingleModelMultipleElementsCommonProperties : SingleModelSingleElementProperty
{ }

SingleModelMultipleElementsCommonProperties 类与 《C#开发BIMFACE系列18 服务端API之获取模型数据3:获取构件属性》 返回的结构类 SingleModelSingleElementProperty 完全相同。

衍生出的一个重载方法:

/// <summary>
/// 获取单个模型的多个构件的共同属性
/// </summary>
/// <param name="accessToken">令牌</param>
/// <param name="fileId">【必填】代表该单模型的文件ID</param>
/// <param name="elementIds">【必填】代表该单模型的构件ID列表</param>
/// <param name="includeOverrides">【非必填】是否查询修改的属性</param>
/// <returns></returns>
public virtual SingleModelMultipleElementsCommonProperties GetSingleModelMultipleElementsCommonProperties(string accessToken, long fileId, List<string> elementIds, bool? includeOverrides = null)
{
return GetSingleModelMultipleElementsCommonProperties(accessToken, fileId, elementIds.ToArray(), includeOverrides);
测试

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

C#开发BIMFACE系列19 服务端API之获取模型数据4:获取多个构件的共同属性

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

C#开发BIMFACE系列19 服务端API之获取模型数据4:获取多个构件的共同属性

测试中查询了 300067,282979,283330 这3个构建的共同属性。完整的属性列表如下:

success
elementId:,, SingleModelSingleElementEntity:
[boundingBox=,
elementId=,
familyGuid=,
Guid=,
name=,
Properties=[group=基本属性,
items=[code=, extension=, key=specialty, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=familyId, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=systemType, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=building, orderNumber=,unit=,value=,valueType=]
]
[group=标识数据,
items=[code=, extension=, key=OmniClass 标题, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=OmniClass 编号, 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=]
[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=]
[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=]
]
[group=限制条件,
items=[code=, extension=, key=偏移量, orderNumber=,unit=mm,value=,valueType=]
]
]

测试代码如下:

// 获取多个构件的共同属性
protected void btnGetSingleModelMultipleElementsCommonProperties_Click(object sender, EventArgs e)
{
FileConvertApi api = new FileConvertApi(); string[] elementIds = txtMultipleElementIds.Text.Split(","); var response = api.GetSingleModelMultipleElementsCommonProperties(txtAccessToken.Text, txtFileID.Text.ToLong(), elementIds, chkIncludeOverrides.Checked); txtResult.Text = response.Code.ToString2()
+ Environment.NewLine
+ "elementId:" + txtMultipleElementIds.Text
+ Environment.NewLine
+ response.Message.ToString2()
+ Environment.NewLine
+ response.Data.ToString();
}