C#开发BIMFACE系列24 服务端API之获取模型数据9:获取单个房间信息

大厦建筑模型中,基本上包含多个楼层,每个楼层包含多个房间等信息。在《C#开发BIMFACE系列21 服务端API之获取模型数据6:获取单模型的楼层信息》中介绍了如何获取一个模型中包含的楼层信息、面积分区、房间等信息。本篇主要介绍如何获取单个模型中单个房间信息。

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

说明:获取单个模型种单个房间信息

参数:

C#开发BIMFACE系列24 服务端API之获取模型数据9:获取单个房间信息

请求 path(示例):https://api.bimface.com/data/v2/files/1211223382064960/rooms/857279

请求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"

HTTP响应示例(200):

{
"code" : "success",
"data" : {
"area" : 7.256476003661832E7,
"bboxMax" : {
"x" : -4938.068482562385,
"y" : -3201.59397858169,
"z" : 0.0
},
"bboxMin" : {
"x" : -4938.068482562385,
"y" : -3201.59397858169,
"z" : 0.0
},
"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" : 40087.80000000279,
"properties" : [ {
"group" : "dimension",
"items" : [ {
"code" : "perimeter",
"extension" : "object",
"key" : "perimeter",
"orderNumber" : ,
"unit" : "mm",
"value" : ,
"valueType" :
} ]
} ]
},
"message" : ""
}

该返回结果的结构比较复杂。在文章最后会给出对应封装成的C#类。

C#实现方法:

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

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

测试

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

C#开发BIMFACE系列24 服务端API之获取模型数据9:获取单个房间信息

以“Revit案例项目改.0001.rvt”为例测试上述的方法。

在《C#开发BIMFACE系列21 服务端API之获取模型数据6:获取单模型的楼层信息》中查询返回的结果中包含 RoomId

C#开发BIMFACE系列24 服务端API之获取模型数据9:获取单个房间信息

以 RoomID 为 857552 为例来查询该房间的详细信息

C#开发BIMFACE系列24 服务端API之获取模型数据9:获取单个房间信息

完整的房间信息如下:

success

[area=70319994.3674652,
bboxMax=[x=13061.9309943162, y=-3481.59383914623, z=2199.99991189159],
bboxMin=[x=7061.93123461209, y=-15201.5933697684, z=],
boundary={"version":"2.0","loops":[[[{"z":0.0,"y":-15201.593978581839,"x":13061.931517437606},
{"z":0.0,"y":-3481.5939785817081,"x":13061.931517437624}
],
[{"z":0.0,"y":-3481.5939785817077,"x":13061.931517437624},
{"z":0.0,"y":-3481.5939785816972,"x":10001.931517437628}
],
[{"z":0.0,"y":-3481.5939785816972,"x":10001.931517437628},
{"z":0.0,"y":-3481.5939785816904,"x":7726.6267896735426}
],
[{"z":0.0,"y":-3481.5939785816904,"x":7726.6267896735426},
{"z":0.0,"y":-3481.59397858169,"x":7558.3362452017109}
],
[{"z":0.0,"y":-3481.59397858169,"x":7558.3362452017109},
{"z":0.0,"y":-3481.5939785816881,"x":7061.9315174376252}
],
[{"z":0.0,"y":-3481.5939785816881,"x":7061.9315174376252},
{"z":0.0,"y":-15201.593978581817,"x":7061.9315174376061}
],
[{"z":0.0,"y":-15201.593978581821,"x":7061.9315174376061},
{"z":0.0,"y":-15201.593978581839,"x":13061.931517437606}
]
]
]
},
id=,
levelId=,
maxPt=[x=13061.9309943162, y=-3481.59383914623, z=],
minPt=[x=7061.93123461209, y=-15201.5933697684, z=],
name=Living ,
perimeter=35579.9985750456,
properties=[group=尺寸标注,
items=[code=, extension=, key=体积, orderNumber=,unit=m³,value=154.70,valueType=]
[code=, extension=, key=周长, orderNumber=,unit=mm,value=,valueType=]
[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=Occupant, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=占用, orderNumber=,unit=,value=,valueType=]
[code=, extension=, key=名称, orderNumber=,unit=,value=Living,valueType=]
[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=]
[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=Working Drawings,valueType=]
]
[group=限制条件,
items=[code=, extension=, key=上限, orderNumber=,unit=,value=Level ,valueType=]
[code=, extension=, key=底部偏移, orderNumber=,unit=mm,value=,valueType=]
[code=, extension=, key=标高, orderNumber=,unit=,value=Level ,valueType=]
[code=, extension=, key=高度偏移, orderNumber=,unit=mm,value=,valueType=]
]
]

测试代码如下:

// 获取单个房间信息
protected void btnGetSingleModelSingleRoom_Click(object sender, EventArgs e)
{
long fileId = txtFileID.Text.Trim().ToLong();
string roomId = txtRoomId.Text.Trim();
FileConvertApi api = new FileConvertApi();
SingleModelSingleRoom response = api.GetSingleModelSingleRoom(txtAccessToken.Text, fileId, roomId); txtResult.Text = response.Code.ToString2()
+ Environment.NewLine
+ response.Message.ToString2()
+ Environment.NewLine
+ response.Data;
}

该接口返回的响应信息,封装成对应的C# SingleModelSingleRoom 类:

/// <summary>
/// 获取单个模型单个房间信息返回的结果类
/// </summary>
public class SingleModelSingleRoom : GeneralResponse<Room>
{ }

Room 类如下:

 /// <summary>
/// 模型的房间信息
/// </summary>
[Serializable]
public class Room
{
/// <summary>
/// 样例 : 7.256476003661832E7
/// </summary>
[JsonProperty("area")]
public double? Area { get; set; } [JsonProperty("bboxMax")]
public Coordinate BboxMax { get; set; } [JsonProperty("bboxMin")]
public Coordinate BboxMin { 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>返回表示当前对象的字符串。</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}, bboxMax={1}, bboxMin={2}, boundary={3}, id={4}, levelId={5}, maxPt={6}, minPt={7}, name={8}, perimeter={9}, properties={10}]",
Area, BboxMax, BboxMin, Boundary, Id, LevelId, MaxPt, MinPt, Name, Perimeter, sb);
}
}

其中 Coordinate 、PropertyGroup 类请参考《C#开发BIMFACE系列17 服务端API之获取模型数据2:获取构件材质列表》

 
 
上一篇:Reads sequentially from multiple sources


下一篇:将存储在本地的大量分散的小文件,合并并保存在hdfs文件系统中