C#開發BIMFACE系列24 服務端API之獲取模型數據9:獲取單個房間信息

大廈建築模型中,基本上包含多個樓層,每一個樓層包含多個房間等信息。在《C#開發BIMFACE系列21 服務端API之獲取模型數據6:獲取單模型的樓層信息》中介紹瞭如何獲取一個模型中包含的樓層信息、面積分區、房間等信息。本篇主要介紹如何獲取單個模型中單個房間信息。html

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

說明:獲取單個模型種單個房間信息ide

參數:oop

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

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

HTTP響應示例(200):url

{ "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" : "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" : 40087.80000000279, "properties" : [ { "group" : "dimension", "items" : [ { "code" : "perimeter", "extension" : "object", "key" : "perimeter", "orderNumber" : 0, "unit" : "mm", "value" : 17200, "valueType" : 2 } ] } ] }, "message" : "" }

該返回結果的結構比較複雜。在文章最後會給出對應封裝成的C#類。spa

C#實現方法:code

 1 /// <summary>
 2 /// 獲取單個模型中單個樓層信息  3 /// </summary>
 4 /// <param name="accessToken">【必填】令牌</param>
 5 /// <param name="fileId">【必填】表明該單模型的文件ID</param>
 6 /// <param name="roomId">【必填】房間ID</param>
 7 /// <returns></returns>
 8 public virtual SingleModelSingleRoom GetSingleModelSingleRoom(string accessToken, long fileId, string roomId)  9 { 10     // GET https://api.bimface.com/data/v2/files/{fileId}/rooms/{roomId}
11     string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/rooms/{1}", fileId, roomId); 12 
13     BimFaceHttpHeaders headers = new BimFaceHttpHeaders(); 14  headers.AddOAuth2Header(accessToken); 15 
16     try
17  { 18  SingleModelSingleRoom 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<SingleModelSingleRoom>(); 25  } 26         else
27  { 28             response = new SingleModelSingleRoom 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系列》orm

測試

在BIMFACE的控制檯中能夠看到如下文件列表。模型狀態均爲轉換成功。

 以「Revit案例項目改.0001.rvt」爲例測試上述的方法。

在《C#開發BIMFACE系列21 服務端API之獲取模型數據6:獲取單模型的樓層信息》中查詢返回的結果中包含 RoomId

以 RoomID 爲 857552 爲例來查詢該房間的詳細信息

完整的房間信息以下:

success [area=70319994.3674652, bboxMax=[x=13061.9309943162, y=-3481.59383914623, z=2199.99991189159], bboxMin=[x=7061.93123461209, y=-15201.5933697684, z=0], 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=857552, levelId=, maxPt=[x=13061.9309943162, y=-3481.59383914623, z=0], minPt=[x=7061.93123461209, y=-15201.5933697684, z=0], name=Living 106, perimeter=35579.9985750456, properties=[group=尺寸標註, items=[code=, extension=, key=體積, orderNumber=,unit=m³,value=154.70,valueType=2] [code=, extension=, key=周長, orderNumber=,unit=mm,value=35580,valueType=2] [code=, extension=, key=房間標示高度, orderNumber=,unit=mm,value=4000,valueType=2] [code=, extension=, key=計算高度, orderNumber=,unit=mm,value=0,valueType=2] [code=, extension=, key=面積, orderNumber=,unit=m²,value=70,valueType=2] ] [group=標識數據, items=[code=, extension=, key=Occupant, orderNumber=,unit=,value=,valueType=3] [code=, extension=, key=佔用, orderNumber=,unit=,value=,valueType=3] [code=, extension=, key=名稱, orderNumber=,unit=,value=Living,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] [code=, extension=, key=編號, orderNumber=,unit=,value=106,valueType=3] [code=, extension=, key=部門, orderNumber=,unit=,value=,valueType=3] ] [group=階段化, items=[code=, extension=, key=相位, orderNumber=,unit=,value=Working Drawings,valueType=4] ] [group=限制條件, items=[code=, extension=, key=上限, orderNumber=,unit=,value=Level 1,valueType=4] [code=, extension=, key=底部偏移, orderNumber=,unit=mm,value=0,valueType=2] [code=, extension=, key=標高, orderNumber=,unit=,value=Level 1,valueType=4] [code=, extension=, key=高度偏移, orderNumber=,unit=mm,value=4000,valueType=2] ] ]

測試代碼以下:

// 獲取單個房間信息
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 類以下:

 1 /// <summary>
 2 /// 模型的房間信息  3 /// </summary>
 4 [Serializable]  5 public class Room  6 {  7     /// <summary>
 8     /// 樣例 : 7.256476003661832E7  9     /// </summary>
10     [JsonProperty("area")] 11     public double? Area { get; set; } 12 
13     [JsonProperty("bboxMax")] 14     public Coordinate BboxMax { get; set; } 15 
16     [JsonProperty("bboxMin")] 17     public Coordinate BboxMin { get; set; } 18 
19     /// <summary>
20     /// 邊界 21     /// </summary>
22     [JsonProperty("boundary")] 23     public string Boundary { get; set; } 24 
25     /// <summary>
26     /// 編號 27     /// </summary>
28     [JsonProperty("id")] 29     public string Id { get; set; } 30 
31     /// <summary>
32     /// 水平線編號 33     /// </summary>
34     [JsonProperty("levelId")] 35     public string LevelId { get; set; } 36 
37     [JsonProperty("maxPt")] 38     public Coordinate MaxPt { get; set; } 39 
40     [JsonProperty("minPt")] 41     public Coordinate MinPt { get; set; } 42 
43     /// <summary>
44     /// 對象名稱。例如:"dining room 4" 45     /// </summary>
46     [JsonProperty("name")] 47     public string Name { get; set; } 48 
49     /// <summary>
50     /// 樣例 : 40087.80000000279 51     /// </summary>
52     [JsonProperty("perimeter")] 53     public double? Perimeter { get; set; } 54 
55     [JsonProperty("properties")] 56     public PropertyGroup[] Properties { get; set; } 57 
58     /// <summary>返回表示當前對象的字符串。</summary>
59     /// <returns>表示當前對象的字符串。</returns>
60     public override string ToString() 61  { 62         StringBuilder sb = new StringBuilder(); 63         if (Properties != null && Properties.Length > 0) 64  { 65             foreach (var property in Properties) 66  { 67  sb.AppendLine(property.ToString()); 68  } 69  } 70 
71         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}]", 72  Area, BboxMax, BboxMin, Boundary, Id, LevelId, MaxPt, MinPt, Name, Perimeter, sb); 73  } 74 }

其中 Coordinate 、PropertyGroup 類請參考《C#開發BIMFACE系列17 服務端API之獲取模型數據2:獲取構件材質列表》

 

相關文章
相關標籤/搜索