在《C#开发BIMFACE系列18 服务端API之获取模型数据3:获取构件属性》中介绍了获取单个文件/模型的单个构建的属性,本篇介绍如何一次性获取多个构建的属性。
请求地址:POST https://api.bimface.com/data/v2/files/{fileId}/elements
说明:支持查询模型属性重写后多个构件的属性,需要设置请求参数includeOverrides的值为true
参数:
其中 ElementPropertyFilterRequest 类如下:
////// 批量获取构件属性的请求参数 /// [Serializable] public class ElementPropertyFilterRequest { /// /// 【必填】构建ID数组。例如: [ "313154", "313047" ] /// [JsonProperty("elementIds")] public string[] ElementIds { get; set; } /// /// 【非必填】过来条件 /// [JsonProperty("filter", NullValueHandling = NullValueHandling.Ignore)] public GroupAndKeysPair[] Filters { get; set; } }
[Serializable] public class GroupAndKeysPair { ////// 分组名称。例如:default、shape、size /// [JsonProperty("group")] public string Group { get; set; } /// /// 关键字数组。例如: [ "length", "width", "a" ] /// [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" : [ "313154", "313047" ], "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" : "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" : "" }
该返回结果中的data部分是一个数组,对应多个构建的属性。与《C#开发BIMFACE系列18 服务端API之获取模型数据3:获取构件属性》中返回的结果相同。
C#实现方法:
1 ///2 /// 批量获取单个模型的多个构件属性 3 /// 4 /// 令牌 5 /// 【必填】代表该单模型的文件ID 6 /// 【必填】请求过滤参数 7 /// 【非必填】是否查询修改的属性 8 /// 9 public virtual SingleModelMultipleElementsProperties GetSingleModelMultipleElementsProperties(string accessToken, long fileId, ElementPropertyFilterRequest request, bool? includeOverrides = null) 10 { 11 if (request == null) 12 { 13 throw new ArgumentException("参数 request 不能为null !"); 14 } 15 16 // POST https://api.bimface.com/data/v2/files/{fileId}/elements 17 string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/elements", fileId); 18 if (includeOverrides != null) 19 { 20 url = url + "?includeOverrides=" + includeOverrides; 21 } 22 23 string data = request.SerializeToJson(); 24 25 BimFaceHttpHeaders headers = new BimFaceHttpHeaders(); 26 headers.AddOAuth2Header(accessToken); 27 28 try 29 { 30 SingleModelMultipleElementsProperties response; 31 32 HttpManager httpManager = new HttpManager(headers); 33 HttpResult httpResult = httpManager.Post(url, data); 34 if (httpResult.Status == HttpResult.STATUS_SUCCESS) 35 { 36 response = httpResult.Text.DeserializeJsonToObject (); 37 } 38 else 39 { 40 response = new SingleModelMultipleElementsProperties 41 { 42 Message = httpResult.RefText 43 }; 44 } 45 46 return response; 47 } 48 catch (Exception ex) 49 { 50 throw new Exception("[批量获取构件属性]发生异常!", ex); 51 } 52 }
其中调用到的 httpManager.Post() 方法,请参考《C# HTTP系列》
其中返回结果类 SingleModelMultipleElementsProperties 定义如下:
////// 批量获取单个模型的多个构件属性返回的结果类 /// [Serializable] public class SingleModelMultipleElementsProperties : GeneralResponse > { }
其中使用了 300067,282979 这2个构建ID。查询的构建属性完整结果如下:
success elementId:300067,282979 SingleModelSingleElementEntity: [boundingBox=[max=[x=5838.783, y=4387.716, z=6000], min=[x=5788.783, y=4237.716, z=5475] ], elementId=300067, familyGuid=2d99307a-66cd-4439-b173-5c88d252416e-00002122, Guid=89c90034-40ae-423a-8935-8f5624db86c1-00049423, name=50 x 150 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=-2000171,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=50 x 150 mm,valueType=] [code=, extension=, key=familyTypeId, orderNumber=,unit=,value=8486,valueType=] [code=, extension=, key=systemType, orderNumber=,unit=,value=,valueType=] [code=, extension=, key=building, orderNumber=,unit=,value=,valueType=] ] [group=尺寸标注, items=[code=, extension=, key=边 1 上的宽度, orderNumber=,unit=mm,value=25,valueType=2] [code=, extension=, key=边 2 上的宽度, orderNumber=,unit=mm,value=25,valueType=2] [code=, extension=, key=长度, orderNumber=,unit=mm,value=525,valueType=2] ] [group=材质和装饰, items=[code=, extension=, key=材质, orderNumber=,unit=,value=金属 - 铝,valueType=4] ] [group=构造, items=[code=, extension=, key=位置, orderNumber=,unit=,value=垂直于面,valueType=4] [code=, extension=, key=厚度, orderNumber=,unit=mm,value=150,valueType=2] [code=, extension=, key=角竖梃, orderNumber=,unit=,value=False,valueType=1] [code=, extension=, key=轮廓, orderNumber=,unit=,value=默认,valueType=4] ] [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] [code=, extension=, key=角度, orderNumber=,unit=°,value=0.00,valueType=2] ] ] SingleModelSingleElementEntity: [boundingBox=[max=[x=-2066.217, y=-7714.284, z=3175], min=[x=-2116.217, y=-7864.284, z=2750] ], elementId=282979, familyGuid=2d99307a-66cd-4439-b173-5c88d252416e-00002122, Guid=0438595c-b6fe-4e10-9b43-4c629826282c-00045163, name=50 x 150 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=-2000171,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=50 x 150 mm,valueType=] [code=, extension=, key=familyTypeId, orderNumber=,unit=,value=8486,valueType=] [code=, extension=, key=systemType, orderNumber=,unit=,value=,valueType=] [code=, extension=, key=building, orderNumber=,unit=,value=,valueType=] ] [group=尺寸标注, items=[code=, extension=, key=边 1 上的宽度, orderNumber=,unit=mm,value=25,valueType=2] [code=, extension=, key=边 2 上的宽度, orderNumber=,unit=mm,value=25,valueType=2] [code=, extension=, key=长度, orderNumber=,unit=mm,value=425,valueType=2] ] [group=材质和装饰, items=[code=, extension=, key=材质, orderNumber=,unit=,value=金属 - 铝,valueType=4] ] [group=构造, items=[code=, extension=, key=位置, orderNumber=,unit=,value=垂直于面,valueType=4] [code=, extension=, key=厚度, orderNumber=,unit=mm,value=150,valueType=2] [code=, extension=, key=角竖梃, orderNumber=,unit=,value=False,valueType=1] [code=, extension=, key=轮廓, orderNumber=,unit=,value=默认,valueType=4] ] [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] [code=, extension=, key=角度, orderNumber=,unit=°,value=0.00,valueType=2] ] ]
测试代码如下:
1 // 批量获取构件属性 2 protected void btnGetSingleModelMultipleElementsProperties_Click(object sender, EventArgs e) 3 { 4 string[] elementIds = txtMultipleElementIds.Text.Split(","); 5 6 ElementPropertyFilterRequest request = new ElementPropertyFilterRequest(); 7 request.ElementIds = elementIds; 8 9 FileConvertApi api = new FileConvertApi(); 10 var response = api.GetSingleModelMultipleElementsProperties(txtAccessToken.Text, txtFileID.Text.ToLong(), request, chkIncludeOverrides.Checked); 11 12 StringBuilder sb = new StringBuilder(); 13 ListlstProperties = response.Data; 14 foreach (var property in lstProperties) 15 { 16 sb.AppendLine(property.ToString()); 17 } 18 txtResult.Text = response.Code.ToString2() 19 + Environment.NewLine 20 + "elementId:" + txtMultipleElementIds.Text 21 + Environment.NewLine 22 + response.Message.ToString2() 23 + Environment.NewLine 24 + sb; 25 }