C#开发BIMFACE系列16 服务端API之获取模型数据1:查询满足条件的构件ID列表

BIMFACE二次开发系列目录     【已更新最新开发文章,点击查看详细】

  源文件/模型转换完成之后,可以获取模型的具体数据。本篇介绍根据文件ID查询满足条件的构件ID列表。

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

说明:根据六个维度(专业,系统类型,楼层,构件类型,族,族类型)获取对应的构件ID列表,任何维度都是可选的。

构件ID分页查询相关请参考这里

同时,也支持根据空间关系从房间计算出房间内的构件ID列表

构件与房间空间关系计算相关请参考这里

参数:

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

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

HTTP响应示例(200):

{
    "code": "success",
    "message": null,
    "data": [
        "1107237",
        "1109326",
        "1107234",
        "1109327",
        "1107235",
        "1107239",
        "1109329",
        "1107236",
        "1109325",
        "1107238",
        "1109328"
    ]
}

C#实现方法:

 1 /// <summary>
 2 ///  查询满足条件的构件ID列表
 3 /// </summary>
 4 /// <param name="accessToken">令牌</param>
 5 /// <param name="fileId">文件ID</param>
 6 /// <param name="request">请求参数对象</param>
 7 /// <returns></returns>
 8 public virtual FileElementsGetResponse GetFileElements(string accessToken, string fileId, FileElementsGetRequest request = null)
 9 {
10     // GET https://api.bimface.com/data/v2/files/{fileId}/elementIds
11     string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/elementIds", fileId);
12 
13     BimFaceHttpHeaders headers = new BimFaceHttpHeaders();
14     headers.AddOAuth2Header(accessToken);
15 
16     string data = string.Empty;
17     if (request != null)
18     {
19         data = request.SerializeToJson();
20     }
21 
22     try
23     {
24         FileElementsGetResponse response;
25 
26         HttpManager httpManager = new HttpManager(headers);
27         HttpResult httpResult = httpManager.Get(url, data);
28         if (httpResult.Status == HttpResult.STATUS_SUCCESS)
29         {
30             response = httpResult.Text.DeserializeJsonToObject<FileElementsGetResponse>();
31         }
32         else
33         {
34             response = new FileElementsGetResponse
35             {
36                 Message = httpResult.RefText
37             };
38         }
39 
40         return response;
41     }
42     catch (Exception ex)
43     {
44         throw new Exception("[查询满足条件的构件ID列表]发生异常!", ex);
45     }
46 }

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

 封装的其他请求参数类 FileElementsGetRequest 

  1 /// <summary>
  2 ///  查询满足条件的构件ID列表请求参数类
  3 /// </summary>
  4 [Serializable]
  5 public class FileElementsGetRequest
  6 {
  7     public FileElementsGetRequest()
  8     {
  9         CategoryId = null;
 10         Family = null;
 11         FamilyType = null;
 12         Floor = null;
 13         PaginationContextId = null;
 14         PaginationNo = null;
 15         PaginationSize = null;
 16         RoomId = null;
 17         RoomToleranceXY = null;
 18         RoomToleranceZ = null;
 19         Specialty = null;
 20         SystemType = null;
 21     }
 22 
 23     ///// <summary>
 24     ///// 【必填】代表该单模型的文件ID
 25     ///// </summary>
 26     //[JsonProperty("fileId")]
 27     //public long FileId { get; set; }
 28 
 29     /// <summary>
 30     ///  【非必填】筛选条件构件类型id
 31     /// </summary>
 32     [JsonProperty("categoryId",NullValueHandling = NullValueHandling.Ignore)]
 33     public string CategoryId { get; set; }
 34 
 35     /// <summary>
 36     ///  【非必填】筛选条件族
 37     /// </summary>
 38     [JsonProperty("family", NullValueHandling = NullValueHandling.Ignore)]
 39     public string Family { get; set; }
 40 
 41     /// <summary>
 42     ///  【非必填】筛选条件族类型
 43     /// </summary>
 44     [JsonProperty("familyType", NullValueHandling = NullValueHandling.Ignore)]
 45     public string FamilyType { get; set; }
 46 
 47     /// <summary>
 48     ///  【非必填】筛选条件楼层
 49     /// </summary>
 50     [JsonProperty("floor", NullValueHandling = NullValueHandling.Ignore)]
 51     public string Floor { get; set; }
 52 
 53     /// <summary>
 54     ///  【非必填】根据paginationContextId返回构件ID列表
 55     /// </summary>
 56     [JsonProperty("paginationContextId", NullValueHandling = NullValueHandling.Ignore)]
 57     public string PaginationContextId { get; set; }
 58 
 59     /// <summary>
 60     ///  【非必填】返回结果中paginationNo对应的页码构件ID项
 61     /// </summary>
 62     [JsonProperty("paginationNo", NullValueHandling = NullValueHandling.Ignore)]
 63     public int? PaginationNo { get; set; }
 64 
 65     /// <summary>
 66     ///  【非必填】返回结果按照paginationSize分页
 67     /// </summary>
 68     [JsonProperty("paginationSize", NullValueHandling = NullValueHandling.Ignore)]
 69     public int? PaginationSize { get; set; }
 70 
 71     /// <summary>
 72     ///  【非必填】筛选条件房间id
 73     /// </summary>
 74     [JsonProperty("roomId", NullValueHandling = NullValueHandling.Ignore)]
 75     public string RoomId { get; set; }
 76 
 77     /// <summary>
 78     ///  【非必填】XY坐标轴方向对构件的筛选容忍度
 79     /// </summary>
 80     [JsonProperty("roomToleranceXY", NullValueHandling = NullValueHandling.Ignore)]
 81     public RoomTolerance? RoomToleranceXY { get; set; }
 82 
 83     /// <summary>
 84     ///  【非必填】Z坐标轴方向对构件的筛选容忍度
 85     /// </summary>
 86     [JsonProperty("roomToleranceZ", NullValueHandling = NullValueHandling.Ignore)]
 87     public RoomTolerance? RoomToleranceZ { get; set; }
 88 
 89     /// <summary>
 90     ///  【非必填】筛选条件专业
 91     /// </summary>
 92     [JsonProperty("specialty", NullValueHandling = NullValueHandling.Ignore)]
 93     public string Specialty { get; set; }
 94 
 95     /// <summary>
 96     ///  【非必填】筛选条件系统类型
 97     /// </summary>
 98     [JsonProperty("systemType", NullValueHandling = NullValueHandling.Ignore)]
 99     public string SystemType { get; set; }
100 }
 1 /// <summary>
 2 ///  坐标轴方向对构件的筛选容忍度
 3 /// </summary>
 4 public enum RoomTolerance
 5 {
 6     STRICT,
 7 
 8     ORDINARY,
 9 
10     LENIENT
11 }

参数都是可选的,如果不设置,则默认不添加到请求中。

测试

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

以“01_BIMFACE示例文件-Revit模型.rvt”为例查询其构建ID列表

查看结果中返回了构建ID列表。

如果使用 .dwg 二维文件进行测试则返回一下信息:unsupported operation:[please upgrade this databag to support specialty tree]

查询满足条件的构件ID列表 ,只对三维模型适用。二维图纸没有目录树。

测试代码如下:

// 查询满足条件的构件ID列表
protected void btnGetFileElements_Click(object sender, EventArgs e)
{
    FileConvertApi api = new FileConvertApi();
    FileElementsGetResponse response = api.GetFileElements(txtAccessToken.Text, txtFileID.Text);

    txtResult.Text = response.Code.ToString2()
                   + Environment.NewLine
                   + response.Message.ToString2()
                   + Environment.NewLine
                   + response.Data.ToStringWith(",");
}

查询构建ID列表返回类 FileElementsGetResponse 

/// <summary>
///  查询满足条件的构件ID列表返回的结果类
/// </summary>
public class FileElementsGetResponse : GeneralResponse<List<string>>
{
}
BIMFACE二次开发系列目录     【已更新最新开发文章,点击查看详细】
posted @ 2019-09-04 17:21  张传宁  阅读(1023)  评论(0编辑  收藏  举报
页脚 HTML 代码