在《C#开发BIMFACE系列22 服务端API之获取模型数据7:获取多个模型的楼层信息》中,返回的楼层信息结果中包含了楼层的具体信息,其中包含楼层ID。
一个楼层中可能包含多个面积分区,本文介绍如何获取楼层对应面积分区列表。
请求地址:GET https://api.bimface.com/data/v2/files/{fileId}/areas
说明:获取单个模型中单个楼层对应的分区列表。
参数:
请求 path(示例):https://api.bimface.com/data/v2/files/1211223382064960/areas?floorId=311
请求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"
HTTP响应示例(200):
{ "code" : "success", "data" : [ { "area" : 5.168684733047761E7, "boundary" : "", "id" : "313137", "levelId" : "11", "maxPt" : { "x" : -4938.068482562385, "y" : -3201.59397858169, "z" : 0.0 }, "minPt" : { "x" : -4938.068482562385, "y" : -3201.59397858169, "z" : 0.0 }, "name" : "dining room 4", "perimeter" : 28802.013920728663, "properties" : [ { "group" : "dimension", "items" : [ { "code" : "perimeter", "extension" : "object", "key" : "perimeter", "orderNumber" : 0, "unit" : "mm", "value" : 17200, "valueType" : 2 } ] } ], "viewName" : "1 1" } ], "message" : "" }
封装成对应的C#类:
/// <summary> /// 获取单个模型种单个楼层对应面积分区列表的返回结果类 /// </summary> public class SingleModelSingleFloorAreas : GeneralResponse<List<Area>> { }
其中 Area 类定义为
/// <summary> /// 楼层区域信息 /// </summary> [Serializable] public class Area { /// <summary> /// 样例 : 7.256476003661832E7 /// </summary> [JsonProperty("area")] public double? AreaValue { get; set; } /// <summary> /// 边界 /// </summary> [JsonProperty("boundary")] public string Boundary { get; set; } /// <summary> /// 编号 /// </summary> [JsonProperty("id")] public string Id { get; set; } /// <summary> /// 水平线编号 /// </summary> [JsonProperty("levelId")] public string LevelId { get; set; } [JsonProperty("maxPt")] public Coordinate MaxPt { get; set; } [JsonProperty("minPt")] public Coordinate MinPt { get; set; } /// <summary> /// 对象名称。例如:"dining room 4" /// </summary> [JsonProperty("name")] public string Name { get; set; } /// <summary> /// 样例 : 40087.80000000279 /// </summary> [JsonProperty("perimeter")] public double? Perimeter { get; set; } [JsonProperty("properties")] public PropertyGroup[] Properties { get; set; } /// <summary> /// 样例 : "1 1" /// </summary> [JsonProperty("viewName")] public string ViewName { get; set; } /// <summary>返回表示当前对象的字符串。</summary> /// <returns>表示当前对象的字符串。</returns> public override string ToString() { StringBuilder sb = new StringBuilder(); if (Properties != null && Properties.Length > 0) { foreach (var property in Properties) { sb.AppendLine(property.ToString()); } } return string.Format("[area={0}, boundary={1}, id={2}, levelId={3}, maxPt={4}, minPt={5}, name={6}, perimeter={7}, properties={8}, viewName={9}]", AreaValue, Boundary, Id, LevelId, MaxPt, MinPt, Name, Perimeter, sb, ViewName); } }
其中 Coordinate 、PropertyGroup 类请参考《C#开发BIMFACE系列17 服务端API之获取模型数据2:获取构件材质列表》。
C#实现方法:
1 /// <summary> 2 /// 获取单个模型中单个楼层对应面积分区列表 3 /// </summary> 4 /// <param name="accessToken">【必填】令牌</param> 5 /// <param name="fileId">【必填】代表该单模型的文件ID</param> 6 /// <param name="floorId">【必填】代表该单模型的楼层ID</param> 7 /// <returns></returns> 8 public virtual SingleModelSingleFloorAreas GetSingleModelSingleFloorAreas(string accessToken, long fileId, string floorId) 9 { 10 // GET https://api.bimface.com/data/v2/files/{fileId}/areas 11 string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/areas?floorId={1}", fileId, floorId); 12 13 BimFaceHttpHeaders headers = new BimFaceHttpHeaders(); 14 headers.AddOAuth2Header(accessToken); 15 16 try 17 { 18 SingleModelSingleFloorAreas response; 19 20 HttpManager httpManager = new HttpManager(headers); 21 HttpResult httpResult = httpManager.Get(url); 22 if (httpResult.Status == HttpResult.STATUS_SUCCESS) 23 { 24 response = httpResult.Text.DeserializeJsonToObject<SingleModelSingleFloorAreas>(); 25 } 26 else 27 { 28 response = new SingleModelSingleFloorAreas 29 { 30 Message = httpResult.RefText 31 }; 32 } 33 34 return response; 35 } 36 catch (Exception ex) 37 { 38 throw new Exception("[获取楼层对应面积分区列表]发生异常!", ex); 39 } 40 }
其中调用到的 httpManager.Get() 方法,请参考《C# HTTP系列》
在BIMFACE的控制台中可以看到我们上传的文件列表,模型状态均为转换成功。
使用“bimface_2018_mdv_room.rvt”为例测试上述方法。
在《C#开发BIMFACE系列22 服务端API之获取模型数据7:获取多个模型的楼层信息》中可以查询到该文件的楼层信息
下面查询 FloorID 等于 245423 的面积分区列表
查询到的完整的面积分区列表为
success [area=4480840.0410909, boundary={"version":"2.0", "loops":[[[{"z":2999.9998798520546,"y":650.40599536995444,"x":6616.83125243813}, {"z":2999.9998798520546,"y":650.40599536996251,"x":4121.9313523570981} ], [{"z":2999.9998798520546,"y":650.40599536996251,"x":4121.9313523570981}, {"z":2999.9998798520546,"y":-1145.5939327014466,"x":4121.9313523570954} ], [{"z":2999.9998798520546,"y":-1145.5939327014466,"x":4121.9313523570945}, {"z":2999.9998798520546,"y":-1145.5939327014546,"x":6616.8312524381263} ], [{"z":2999.9998798520546,"y":-1145.5939327014546,"x":6616.8312524381263}, {"z":2999.9998798520546,"y":650.40599536995444,"x":6616.83125243813} ] ] ] }, id=1092832, levelId=, maxPt=[x=6616.83125243813, y=650.405995369963, z=2999.99987985205], minPt=[x=4121.93135235709, y=-1145.59393270145, z=2999.99987985205], name=面积 2, perimeter=8101.79967552855, properties=, viewName= ] [area=4333552.00744229, boundary={"version":"2.0", "loops":[[[{"z":2999.9998798520546,"y":-3201.5938503598827,"x":4505.6454184675295}, {"z":2999.9998798520546,"y":-3201.5938503598904,"x":7001.9312370150637} ], [{"z":2999.9998798520546,"y":-3302.5938463149096,"x":7001.9312370150637}, {"z":2999.9998798520546,"y":-1465.5939198856749,"x":7001.9312370150674} ], [{"z":2999.9998798520546,"y":-1465.5939198856749,"x":7001.9312370150665}, {"z":2999.9998798520546,"y":-1465.5939198856668,"x":4505.6454184675331} ], [{"z":2999.9998798520546,"y":-1465.5939198856677,"x":4505.6454184675331}, {"z":2999.9998798520546,"y":-3302.5938463149018,"x":4505.64541846753} ] ] ] }, id=1092841, levelId=, maxPt=[x=7001.93123701507, y=-1465.59391988567, z=2999.99987985205], minPt=[x=4505.64541846753, y=-3302.59384631491, z=2999.99987985205], name=面积 3, perimeter=8104.57151246125, properties=, viewName= ]
测试代码如下:
// 获取楼层对应面积分区列表 protected void btnGetSingleModelSingleFloorAreas_Click(object sender, EventArgs e) { long fileId = txtFileID.Text.Trim().ToLong(); string floorId = txtFloorId.Text.Trim(); FileConvertApi api = new FileConvertApi(); SingleModelSingleFloorAreas response = api.GetSingleModelSingleFloorAreas(txtAccessToken.Text, fileId, floorId); txtResult.Text = response.Code.ToString2() + Environment.NewLine + response.Message.ToString2() + Environment.NewLine + response.Data.ToStringLine(); }
文章来源: 博客园
- 还没有人评论,欢迎说说您的想法!