在前几篇博客中介绍了一个三维文件/模型包含多个构建,每个构建又是由多种材质组成,每个构建都有很多属性。不同的构建也有可能包含相同的属性。
上图中可以看到构建1与构建2拥有相同的属性2,构建2与构建n拥有相同的属性1。
本文主要介绍如何获取多个构建的共同属性。
请求地址:GET https://api.bimface.com/data/v2/files/{fileId}/commonElementProperties
说明:若传入的elementId不止一个,则返回这些elementId共同的属性,共同的定义为:属性key与value都相等。
支持查询模型属性重写后多个构件的共同属性,需要设置请求参数includeOverrides的值为true。
参数:
请求 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" : "313052", "familyGuid" : "000222", "guid" : "79d547c1-5dbf-4e6a-811d-951cf37b29da-0004c6dc", "name" : "norm - 150mm", "properties" : [ { "group" : "dimension", "items" : [ { "code" : "perimeter", "extension" : "object", "key" : "perimeter", "orderNumber" : 0, "unit" : "mm", "value" : 17200, "valueType" : 2 } ] } ] }, "message" : "" }
C#实现方法:
1 ///2 /// 获取单个模型的多个构件的共同属性 3 /// 4 /// 令牌 5 /// 【必填】代表该单模型的文件ID 6 /// 【必填】代表该单模型的构件ID列表 7 /// 【非必填】是否查询修改的属性 8 /// 9 public virtual SingleModelMultipleElementsCommonProperties GetSingleModelMultipleElementsCommonProperties(string accessToken, long fileId, string[] elementIds, bool? includeOverrides = null) 10 { 11 if (elementIds == null && elementIds.Length == 0) 12 { 13 throw new ArgumentException("参数 elementIds 不能为null 且必须包含元素!"); 14 } 15 16 // GET https://api.bimface.com/data/v2/files/{fileId}/commonElementProperties?elementIds={string} 17 string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/commonElementProperties?elementIds={1}", fileId, elementIds.ToStringWith(",")); 18 if (includeOverrides != null) 19 { 20 url = url + "&includeOverrides=" + includeOverrides; 21 } 22 23 BimFaceHttpHeaders headers = new BimFaceHttpHeaders(); 24 headers.AddOAuth2Header(accessToken); 25 26 try 27 { 28 SingleModelMultipleElementsCommonProperties response; 29 30 HttpManager httpManager = new HttpManager(headers); 31 HttpResult httpResult = httpManager.Get(url); 32 if (httpResult.Status == HttpResult.STATUS_SUCCESS) 33 { 34 response = httpResult.Text.DeserializeJsonToObject (); 35 } 36 else 37 { 38 response = new SingleModelMultipleElementsCommonProperties 39 { 40 Message = httpResult.RefText 41 }; 42 } 43 44 return response; 45 } 46 catch (Exception ex) 47 { 48 throw new Exception("[获取多个构件的共同属性]发生异常!", ex); 49 } 50 }
其中调用到的 httpManager.Get() 方法,请参考《C# HTTP系列》
响应结果对应的实体类 SingleModelMultipleElementsCommonProperties ,封装如下:
////// 获取多个构件的共同属性返回的结果类 /// public class SingleModelMultipleElementsCommonProperties : SingleModelSingleElementProperty { }
SingleModelMultipleElementsCommonProperties 类与 《C#开发BIMFACE系列18 服务端API之获取模型数据3:获取构件属性》 返回的结构类 SingleModelSingleElementProperty 完全相同。
衍生出的一个重载方法:
////// 获取单个模型的多个构件的共同属性 /// /// 令牌 /// 【必填】代表该单模型的文件ID /// 【必填】代表该单模型的构件ID列表 /// 【非必填】是否查询修改的属性 /// public virtual SingleModelMultipleElementsCommonProperties GetSingleModelMultipleElementsCommonProperties(string accessToken, long fileId, List<string> elementIds, bool? includeOverrides = null) { return GetSingleModelMultipleElementsCommonProperties(accessToken, fileId, elementIds.ToArray(), includeOverrides); }
测试中查询了 300067,282979,283330 这3个构建的共同属性。完整的属性列表如下:
success elementId:300067,282979,283330 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=3] [code=, extension=, key=OmniClass 编号, orderNumber=,unit=,value=,valueType=3] [code=, extension=, key=URL, 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=4] [code=, extension=, key=型号, orderNumber=,unit=,value=,valueType=3] [code=, extension=, key=成本, 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=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=4] [code=, extension=, key=拆除的阶段, orderNumber=,unit=,value=无,valueType=4] ] [group=限制条件, items=[code=, extension=, key=偏移量, orderNumber=,unit=mm,value=0,valueType=2] ] ]
测试代码如下:
// 获取多个构件的共同属性 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(); }