在《C#开发BIMFACE系列25 服务端API之获取模型数据9:获取楼层对应面积分区列表》一文中介绍了如何获取单个模型中单个楼层包含的面积分区列表。有了面积分区列表之后,即可查询单个面积分区的具体信息。
请求地址:GET https://api.bimface.com/data/v2/files/{fileId}/areas
说明:获取单个模型中单个面积分区包含的信息
参数:
请求 path(示例):https://api.bimface.com/data/v2/files/1211223382064960/areas/313467
请求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"
HTTP响应示例(200):
{
"code" : "success",
"data" : {
"area" : 5.168684733047761E7,
"boundary" : "",
"id" : "",
"levelId" : "",
"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" : ,
"unit" : "mm",
"value" : ,
"valueType" :
} ]
} ],
"viewName" : "1 1"
},
"message" : ""
}
封装成对应的C#类如下:
/// <summary>
/// 获取单个面积分区信息返回的结果类
/// </summary>
[Serializable]
public class SingleModelSingleArea : GeneralResponse<Area>
{ }
其中 Area 类,请参考《C#开发BIMFACE系列25 服务端API之获取模型数据10:获取楼层对应面积分区列表》。
C#实现方法:
/// <summary>
/// 获取单个模型中单个面积分区信息
/// </summary>
/// <param name="accessToken">【必填】令牌</param>
/// <param name="fileId">【必填】代表该单模型的文件ID</param>
/// <param name="areaId">【必填】面积分区ID</param>
/// <returns></returns>
public virtual SingleModelSingleArea GetSingleModelSingleArea(string accessToken, long fileId, string areaId)
{
// GET https://api.bimface.com/data/v2/files/{fileId}/areas/{areaId}
string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/areas/{1}", fileId, areaId); BimFaceHttpHeaders headers = new BimFaceHttpHeaders();
headers.AddOAuth2Header(accessToken); try
{
SingleModelSingleArea response; HttpManager httpManager = new HttpManager(headers);
HttpResult httpResult = httpManager.Get(url);
if (httpResult.Status == HttpResult.STATUS_SUCCESS)
{
response = httpResult.Text.DeserializeJsonToObject<SingleModelSingleArea>();
}
else
{
response = new SingleModelSingleArea
{
Message = httpResult.RefText
};
} return response;
}
catch (Exception ex)
{
throw new Exception("[获取单个面积分区信息]发生异常!", ex);
}
}
其中调用到的 httpManager.Get() 方法,请参考《C# HTTP系列》
在BIMFACE的控制台中可以看到我们上传的文件列表,模型状态均为转换成功。
使用“bimface_2018_mdv_room.rvt”为例测试上述方法。
在《C#开发BIMFACE系列25 服务端API之获取模型数据10:获取楼层对应面积分区列表》中返回了2个面积分区ID,分别是1092832与1092841。
1092841完整的面积分区信息如下:
success [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=,
levelId=,
maxPt=[x=7001.93123701507, y=-1465.59391988567, z=2999.99987985205],
minPt=[x=4505.64541846753, y=-3302.59384631491, z=2999.99987985205],
name=面积 ,
perimeter=8104.57151246125,
properties=[group=其他,
items=[code=, extension=, key=面积类型, 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=m²,value=,valueType=]
]
[group=标识数据,
items=[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=Level ,valueType=]
],
viewName=
]
测试代码如下:
// 获取单个面积分区信息
protected void btnGetSingleModelSingleArea_Click(object sender, EventArgs e)
{
long fileId = txtFileID.Text.Trim().ToLong();
string areaId = txtAreaId.Text.Trim();
FileConvertApi api = new FileConvertApi();
SingleModelSingleArea response = api.GetSingleModelSingleArea(txtAccessToken.Text, fileId, areaId); txtResult.Text = response.Code.ToString2()
+ Environment.NewLine
+ response.Message.ToString2()
+ Environment.NewLine
+ response.Data;
}