C#开发BIMFACE系列20 服务端API之获取模型数据5:批量获取构件属性

在《C#开发BIMFACE系列18 服务端API之获取模型数据3:获取构件属性》中介绍了获取单个文件/模型的单个构建的属性,本篇介绍如何一次性获取多个构建的属性。

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

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

参数:

C#开发BIMFACE系列20 服务端API之获取模型数据5:批量获取构件属性

其中 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/elements

若需查询重写后的构件属性,请求示例为

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

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

请求 body(示例):

{
"elementIds" : [ "", "" ],
"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" : "",
"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" : ""
}

该返回结果中的data部分是一个数组,对应多个构建的属性。与《C#开发BIMFACE系列18 服务端API之获取模型数据3:获取构件属性》中返回的结果相同。

C#实现方法:

 /// <summary>
/// 批量获取单个模型的多个构件属性
/// </summary>
/// <param name="accessToken">令牌</param>
/// <param name="fileId">【必填】代表该单模型的文件ID</param>
/// <param name="request">【必填】请求过滤参数</param>
/// <param name="includeOverrides">【非必填】是否查询修改的属性</param>
/// <returns></returns>
public virtual SingleModelMultipleElementsProperties GetSingleModelMultipleElementsProperties(string accessToken, long fileId, ElementPropertyFilterRequest request, bool? includeOverrides = null)
{
if (request == null)
{
throw new ArgumentException("参数 request 不能为null !");
} // POST https://api.bimface.com/data/v2/files/{fileId}/elements
string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/elements", fileId);
if (includeOverrides != null)
{
url = url + "?includeOverrides=" + includeOverrides;
} string data = request.SerializeToJson(); BimFaceHttpHeaders headers = new BimFaceHttpHeaders();
headers.AddOAuth2Header(accessToken); try
{
SingleModelMultipleElementsProperties response; HttpManager httpManager = new HttpManager(headers);
HttpResult httpResult = httpManager.Post(url, data);
if (httpResult.Status == HttpResult.STATUS_SUCCESS)
{
response = httpResult.Text.DeserializeJsonToObject<SingleModelMultipleElementsProperties>();
}
else
{
response = new SingleModelMultipleElementsProperties
{
Message = httpResult.RefText
};
} return response;
}
catch (Exception ex)
{
throw new Exception("[批量获取构件属性]发生异常!", ex);
}
}

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

其中返回结果类  SingleModelMultipleElementsProperties 定义如下:

/// <summary>
/// 批量获取单个模型的多个构件属性返回的结果类
/// </summary>
[Serializable]
public class SingleModelMultipleElementsProperties : GeneralResponse<List<SingleModelSingleElementEntity>>
{ }
测试

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

C#开发BIMFACE系列20 服务端API之获取模型数据5:批量获取构件属性

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

C#开发BIMFACE系列20 服务端API之获取模型数据5:批量获取构件属性

其中使用了 300067,282979 这2个构建ID。查询的构建属性完整结果如下:

success
elementId:, SingleModelSingleElementEntity:
[boundingBox=[max=[x=5838.783, y=4387.716, z=],
min=[x=5788.783, y=4237.716, z=]
],
elementId=,
familyGuid=2d99307a-66cd--b173-5c88d252416e-,
Guid=89c90034-40ae-423a--8f5624db86c1-,
name= x 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=-,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= x mm,valueType=]
[code=, extension=, key=familyTypeId, 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=边 上的宽度, orderNumber=,unit=mm,value=,valueType=]
[code=, extension=, key=边 上的宽度, orderNumber=,unit=mm,value=,valueType=]
[code=, extension=, key=长度, orderNumber=,unit=mm,value=,valueType=]
]
[group=材质和装饰,
items=[code=, extension=, key=材质, orderNumber=,unit=,value=金属 - 铝,valueType=]
]
[group=构造,
items=[code=, extension=, key=位置, orderNumber=,unit=,value=垂直于面,valueType=]
[code=, extension=, key=厚度, orderNumber=,unit=mm,value=,valueType=]
[code=, extension=, key=角竖梃, orderNumber=,unit=,value=False,valueType=]
[code=, extension=, key=轮廓, 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=]
[code=, extension=, key=角度, orderNumber=,unit=°,value=0.00,valueType=]
]
] SingleModelSingleElementEntity:
[boundingBox=[max=[x=-2066.217, y=-7714.284, z=],
min=[x=-2116.217, y=-7864.284, z=]
],
elementId=,
familyGuid=2d99307a-66cd--b173-5c88d252416e-,
Guid=0438595c-b6fe-4e10-9b43-4c629826282c-,
name= x 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=-,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= x mm,valueType=]
[code=, extension=, key=familyTypeId, 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=边 上的宽度, orderNumber=,unit=mm,value=,valueType=]
[code=, extension=, key=边 上的宽度, orderNumber=,unit=mm,value=,valueType=]
[code=, extension=, key=长度, orderNumber=,unit=mm,value=,valueType=]
]
[group=材质和装饰,
items=[code=, extension=, key=材质, orderNumber=,unit=,value=金属 - 铝,valueType=]
]
[group=构造,
items=[code=, extension=, key=位置, orderNumber=,unit=,value=垂直于面,valueType=]
[code=, extension=, key=厚度, orderNumber=,unit=mm,value=,valueType=]
[code=, extension=, key=角竖梃, orderNumber=,unit=,value=False,valueType=]
[code=, extension=, key=轮廓, 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=]
[code=, extension=, key=角度, orderNumber=,unit=°,value=0.00,valueType=]
]
]

测试代码如下:

 // 批量获取构件属性
protected void btnGetSingleModelMultipleElementsProperties_Click(object sender, EventArgs e)
{
string[] elementIds = txtMultipleElementIds.Text.Split(","); ElementPropertyFilterRequest request = new ElementPropertyFilterRequest();
request.ElementIds = elementIds; FileConvertApi api = new FileConvertApi();
var response = api.GetSingleModelMultipleElementsProperties(txtAccessToken.Text, txtFileID.Text.ToLong(), request, chkIncludeOverrides.Checked); StringBuilder sb = new StringBuilder();
List<SingleModelSingleElementEntity> lstProperties = response.Data;
foreach (var property in lstProperties)
{
sb.AppendLine(property.ToString());
}
txtResult.Text = response.Code.ToString2()
+ Environment.NewLine
+ "elementId:" + txtMultipleElementIds.Text
+ Environment.NewLine
+ response.Message.ToString2()
+ Environment.NewLine
+ sb;
}
 
上一篇:C#开发BIMFACE系列17 服务端API之获取模型数据2:获取构件材质列表


下一篇:C#开发BIMFACE系列25 服务端API之获取模型数据10:获取楼层对应面积分区列表