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

在《C#开发BIMFACE系列22 服务端API之获取模型数据7:获取多个模型的楼层信息》中,返回的楼层信息结果中包含了楼层的具体信息,其中包含楼层ID。

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

一个楼层中可能包含多个面积分区,本文介绍如何获取楼层对应面积分区列表。

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

说明:获取单个模型中单个楼层对应的分区列表。

参数:

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

请求 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" : "",
"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>
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 > )
{
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#实现方法:

 /// <summary>
/// 获取单个模型中单个楼层对应面积分区列表
/// </summary>
/// <param name="accessToken">【必填】令牌</param>
/// <param name="fileId">【必填】代表该单模型的文件ID</param>
/// <param name="floorId">【必填】代表该单模型的楼层ID</param>
/// <returns></returns>
public virtual SingleModelSingleFloorAreas GetSingleModelSingleFloorAreas(string accessToken, long fileId, string floorId)
{
// GET https://api.bimface.com/data/v2/files/{fileId}/areas
string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/areas?floorId={1}", fileId, floorId); BimFaceHttpHeaders headers = new BimFaceHttpHeaders();
headers.AddOAuth2Header(accessToken); try
{
SingleModelSingleFloorAreas response; HttpManager httpManager = new HttpManager(headers);
HttpResult httpResult = httpManager.Get(url);
if (httpResult.Status == HttpResult.STATUS_SUCCESS)
{
response = httpResult.Text.DeserializeJsonToObject<SingleModelSingleFloorAreas>();
}
else
{
response = new SingleModelSingleFloorAreas
{
Message = httpResult.RefText
};
} return response;
}
catch (Exception ex)
{
throw new Exception("[获取楼层对应面积分区列表]发生异常!", ex);
}
}

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

测试

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

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

使用“bimface_2018_mdv_room.rvt”为例测试上述方法。

在《C#开发BIMFACE系列22 服务端API之获取模型数据7:获取多个模型的楼层信息》中可以查询到该文件的楼层信息

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

下面查询 FloorID 等于 245423 的面积分区列表

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

查询到的完整的面积分区列表为

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=,
levelId=,
maxPt=[x=6616.83125243813, y=650.405995369963, z=2999.99987985205],
minPt=[x=4121.93135235709, y=-1145.59393270145, z=2999.99987985205],
name=面积 , 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=,
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=,
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();
}
 
上一篇:C#开发BIMFACE系列20 服务端API之获取模型数据5:批量获取构件属性


下一篇:Python自动化之django视图