BIMFACE官方示例中,加载三维模型后,模型浏览器中左上角默认提供了“目录树”的功能,清晰地展示了模型的完整构成及上下级关系。

本篇介绍如何获取单个模型的构件分类树信息。

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

说明:单模型构件分类树, treeType 接受两个值:default 和 customized,默认为 default。

v参数用来区别 treeType 为 default 时返回树的格式, customized总是返回格式2.0的构件树。

参数:

v参数用来区别 treeType 为 default 时返回树的格式, customized总是返回格式2.0的构件树。

当 treeType 为"customized"时,desiredHierarchy 表示了筛选树的层次,可选值有building,systemType,specialty,floor,category,family,familyType,如:desiredHierarchy=specialty,systemtype。

customizedNodeKeys:用来指定筛选树每个维度用id或者是name作为唯一标识, 如"floor":"id"。

请求2.0的默认分类树(floor, category, family, familyType)

请求 path(示例):https://api.bimface.com/data/v2/files/1211223382064960/tree?v=2.0

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

请求 body(示例):可以为空,不传递。

HTTP响应示例(200):

  1. {
  2. "code": "success",
  3. "message": null,
  4. "data": [
  5. {
  6. "actualName": "1F",
  7. "data": null,
  8. "elementCount": ,
  9. "id": "",
  10. "items": [
  11. {
  12. "actualName": "栏杆扶手",
  13. "data": null,
  14. "elementCount": ,
  15. "id": "-2000126",
  16. "items": [
  17. {
  18. "actualName": "栏杆扶手",
  19. "data": null,
  20. "elementCount": ,
  21. "id": "",
  22. "items": [
  23. {
  24. "actualName": "栏杆",
  25. "data": null,
  26. "elementCount": ,
  27. "id": null,
  28. "items": [],
  29. "name": "栏杆",
  30. "type": "familyType"
  31. }
  32. ],
  33. "name": "栏杆扶手",
  34. "type": "family"
  35. }
  36. ],
  37. "name": "栏杆扶手",
  38. "type": "category"
  39. }
  40. ],
  41. "name": "1F",
  42. "type": "floor"
  43. }
  44. ]
  45. }

返回的结果结构比较复杂,封装成对应的C#类如下:

  1. /// <summary>
  2. /// 获取单个模型的构件分类树(2.0的默认分类树 floor, category, family, familyType)返回的结果类(默认模式)
  3. /// </summary>
  4. [Serializable]
  5. public class SingleModelTree : GeneralResponse<List<TreeItem>>
  6. {
  7.  
  8. }

调用的 TreeItem 类

  1. [Serializable]
  2. public class TreeItem
  3. {
  4. /// <summary>
  5. /// 项的名称
  6. /// </summary>
  7. [JsonProperty("actualName")]
  8. public string ActualName { get; set; }
  9.  
  10. [JsonProperty("data")]
  11. public string Data { get; set; }
  12.  
  13. [JsonProperty("elementCount")]
  14. public int? ElementCount { get; set; }
  15.  
  16. [JsonProperty("id")]
  17. public string Id { get; set; }
  18.  
  19. [JsonProperty("items")]
  20. public TreeItem[] Items { get; set; }
  21.  
  22. [JsonProperty("name")]
  23. public string Name { get; set; }
  24.  
  25. /// <summary>
  26. /// 例如:familyType、family、category
  27. /// </summary>
  28. [JsonProperty("type")]
  29. public string Type { get; set; }
  30.  
  31. /// <summary>返回表示当前对象的字符串。</summary>
  32. /// <returns>表示当前对象的字符串。</returns>
  33. public override string ToString()
  34. {
  35. return String.Format("[actualName={0}, data={1}, elementCount={2}, id={3}, items={4}, name={5}, type={6}]",
  36. ActualName, Data, ElementCount, Id, Items.ToStringLine(), Name, Type);
  37. }
  38. }

请注意 TreeItem 类中的 public TreeItem[] Items { get; set; } 属性,类型是该类本身。属于递归引用。

Newtonsoft.Json.dll 默认支持递归引用类的序列化与反序列化。

C#实现方法:

  1. /// <summary>
  2. /// 获取单个模型中构件的默认分类树
  3. /// </summary>
  4. /// <param name="accessToken">【必填】令牌</param>
  5. /// <param name="fileId">【必填】代表该单模型的文件ID</param>
  6. /// <param name="v">【非必填】用来区别treeType为default时返回树的格式</param>
  7. /// <param name="request">【非必填】其他过滤参数类对象</param>
  8. /// <returns></returns>
  9. public virtual SingleModelTree GetSingleModelTreeByDefault(string accessToken, long fileId, string v = "2.0", FileTreeRequestBody request = null)
  10. {
  11. //return GetSingleModelTree(accessToken, fileId, TreeType.Default, v, request);
  12. /* 单模型构件分类树,
  13. (1)treeType 接受两个值:default 和 customized,默认为 default。
  14. (2)v 参数用来区别 treeType 为 default 时返回树的格式, customized 总是返回格式2.0的构件树。
  15. (3)当 treeType 为"customized"时,FileTreeRequestBody 类的 desiredHierarchy 属性 表示了筛选树的层次,可选值有building,systemType,specialty,floor,category,family,familyType,
  16. 如:desiredHierarchy=specialty,systemtype。
  17. customizedNodeKeys: 用来指定筛选树每个维度用id或者是name作为唯一标识, 如"floor":"id"
  18. */
  19.  
  20. // POST https://api.bimface.com/data/v2/files/{fileId}/tree
  21. string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/tree?treeType=default", fileId);
  22.  
  23. if (!string.IsNullOrWhiteSpace(v))
  24. {
  25. url = url + "&v=" + v;
  26. }
  27.  
  28. string data = string.Empty;
  29. if (request != null)
  30. {
  31. data = request.SerializeToJson();
  32. }
  33.  
  34. BimFaceHttpHeaders headers = new BimFaceHttpHeaders();
  35. headers.AddOAuth2Header(accessToken);
  36.  
  37. try
  38. {
  39. SingleModelTree response;
  40.  
  41. HttpManager httpManager = new HttpManager(headers);
  42. HttpResult httpResult = httpManager.Post(url, data);
  43. if (httpResult.Status == HttpResult.STATUS_SUCCESS)
  44. {
  45. response = httpResult.Text.DeserializeJsonToObject<SingleModelTree>();
  46. }
  47. else
  48. {
  49. response = new SingleModelTree
  50. {
  51. Message = httpResult.RefText
  52. };
  53. }
  54.  
  55. return response;
  56. }
  57. catch (Exception ex)
  58. {
  59. throw new Exception("[获取单个模型中构件的默认分类树]发生异常!", ex);
  60. }
  61. }

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

测试:

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

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

完整的分类树为

  1. success
  2.  
  3. [
  4. {
  5. "actualName": "标高 1",
  6. "data": null,
  7. "elementCount": ,
  8. "id": "",
  9. "items": [
  10. {
  11. "actualName": "墙",
  12. "data": null,
  13. "elementCount": ,
  14. "id": "-2000011",
  15. "items": [
  16. {
  17. "actualName": "基本墙",
  18. "data": null,
  19. "elementCount": ,
  20. "id": "",
  21. "items": [
  22. {
  23. "actualName": "常规 - 200mm",
  24. "data": null,
  25. "elementCount": ,
  26. "id": "",
  27. "items": [],
  28. "name": "常规 - 200mm",
  29. "type": "familyType"
  30. }
  31. ],
  32. "name": "基本墙",
  33. "type": "family"
  34. }
  35. ],
  36. "name": "墙",
  37. "type": "category"
  38. }
  39. ],
  40. "name": "标高 1",
  41. "type": "floor"
  42. }
  43. ]

测试代码如下:

  1. // 获取构件分类树(默认)
  2. protected void btnGetSingleModelTreeByDefault_Click(object sender, EventArgs e)
  3. {
  4. long fileId = txtFileID.Text.Trim().ToLong();
  5. FileConvertApi api = new FileConvertApi();
  6. SingleModelTree response = api.GetSingleModelTreeByDefault(txtAccessToken.Text, fileId);
  7.  
  8. txtResult.Text = response.Code.ToString2()
  9. + Environment.NewLine
  10. + response.Message.ToString2()
  11. + Environment.NewLine
  12. + response.Data.ToStringLine();
  13. }
请求自定义树(floor, category, family, familyType)

请求 path(示例):https://api.bimface.com/data/v2/files/1211223382064960/tree?v=2.0&treeType=customized

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

请求 body(示例):

  1. {
  2. "desiredHierarchy": [
  3. "category",
  4. "family"
  5. ],
  6. "customizedNodeKeys": {
  7. "category": "name"
  8. }
  9. }

请求体不能为 NULL ,必须传递值。 否则请求失败,提示 system.error.  customized tree request body is null

HTTP响应示例(200):

  1. {
  2. "code": "success",
  3. "message": null,
  4. "data": {
  5. "items": [
  6. {
  7. "actualName": "专用设备",
  8. "data": null,
  9. "elementCount": ,
  10. "id": "-2001350",
  11. "items": [
  12. {
  13. "actualName": "投影仪-基于天花板 3D",
  14. "data": null,
  15. "elementCount": ,
  16. "id": "",
  17. "items": [
  18.  
  19. ],
  20. "name": "投影仪-基于天花板 3D",
  21. "type": "family"
  22. },
  23. {
  24. "actualName": "投影屏幕-基于天花板 3D",
  25. "data": null,
  26. "elementCount": ,
  27. "id": "",
  28. "items": [
  29.  
  30. ],
  31. "name": "投影屏幕-基于天花板 3D",
  32. "type": "family"
  33. }
  34. ],
  35. "name": "卫浴装置",
  36. "type": "category"
  37. }
  38. ],
  39. "root": "category"
  40. }
  41. }

返回的结果结构比较复杂,封装成对应的C#类如下:

  1. /// <summary>
  2. /// 获取单个模型的构件分类树(自定义树floor, category, family, familyType)返回的结果类
  3. /// </summary>
  4. [Serializable]
  5. public class SingleModelTreeByCustomized : GeneralResponse<SingleModelTreeByCustomized>
  6. {
  7. [JsonProperty("root")]
  8. public string Root { get; set; }
  9.  
  10. [JsonProperty("items")]
  11. public TreeItem[] Items { get; set; }
  12.  
  13. /// <summary>返回表示当前对象的字符串。</summary>
  14. /// <returns>表示当前对象的字符串。</returns>
  15. public override string ToString()
  16. {
  17. return String.Format("[root={0}, items={1}]",
  18. Root, Items.ToStringLine());
  19. }
  20. }

C#实现方法:

  1. /// <summary>
  2. /// 获取单个模型中构件的自定义分类树
  3. /// </summary>
  4. /// <param name="accessToken">【必填】令牌</param>
  5. /// <param name="fileId">【必填】代表该单模型的文件ID</param>
  6. /// <param name="v">【非必填】用来区别treeType为default时返回树的格式</param>
  7. /// <param name="request">【非必填】其他过滤参数类对象</param>
  8. /// <returns></returns>
  9. public virtual SingleModelTreeByCustomized GetSingleModelTreeByCustomized(string accessToken, long fileId, string v = "2.0", FileTreeRequestBody request = null)
  10. {
  11. //return GetSingleModelTree(accessToken, fileId, TreeType.Default, v, request);
  12. /* 单模型构件分类树,
  13. (1)treeType 接受两个值:default 和 customized,默认为 default。
  14. (2)v 参数用来区别 treeType 为 default 时返回树的格式, customized 总是返回格式2.0的构件树。
  15. (3)当 treeType 为"customized"时,FileTreeRequestBody 类的 desiredHierarchy 属性 表示了筛选树的层次,可选值有building,systemType,specialty,floor,category,family,familyType,
  16. 如:desiredHierarchy=specialty,systemtype。
  17. customizedNodeKeys: 用来指定筛选树每个维度用id或者是name作为唯一标识, 如"floor":"id"
  18. */
  19.  
  20. // POST https://api.bimface.com/data/v2/files/{fileId}/tree
  21. string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/tree?treeType=customized", fileId);
  22.  
  23. if (!string.IsNullOrWhiteSpace(v))
  24. {
  25. url = url + "&v=" + v;
  26. }
  27.  
  28. string data = string.Empty;
  29. if (request != null)
  30. {
  31. data = request.SerializeToJson();
  32. }
  33.  
  34. BimFaceHttpHeaders headers = new BimFaceHttpHeaders();
  35. headers.AddOAuth2Header(accessToken);
  36.  
  37. try
  38. {
  39. SingleModelTreeByCustomized response;
  40.  
  41. HttpManager httpManager = new HttpManager(headers);
  42. HttpResult httpResult = httpManager.Post(url, data);
  43. if (httpResult.Status == HttpResult.STATUS_SUCCESS)
  44. {
  45. response = httpResult.Text.DeserializeJsonToObject<SingleModelTreeByCustomized>();
  46. }
  47. else
  48. {
  49. response = new SingleModelTreeByCustomized
  50. {
  51. Message = httpResult.RefText
  52. };
  53. }
  54.  
  55. return response;
  56. }
  57. catch (Exception ex)
  58. {
  59. throw new Exception("[获取单个模型中构件的自定义分类树]发生异常!", ex);
  60. }
  61. }

测试:

同样使用“A4.rvt”为例测试上述方法。

完整的分类树为

  1. success
  2.  
  3. [root=单体,
  4. items=[actualName=,
  5. data=,
  6. elementCount=,
  7. id=,
  8. items=[actualName=,
  9. data=,
  10. elementCount=,
  11. id=,
  12. items=[actualName=,
  13. data=,
  14. elementCount=,
  15. id=,
  16. items=[actualName=标高 ,
  17. data=,
  18. elementCount=,
  19. id=,
  20. items=[actualName=墙,
  21. data=,
  22. elementCount=,
  23. id=-,
  24. items=[actualName=基本墙,
  25. data=,
  26. elementCount=,
  27. id=,
  28. items=[actualName=常规 - 200mm,
  29. data=,
  30. elementCount=,
  31. id=,
  32. items=,
  33. name=常规 - 200mm,
  34. type=familyType
  35. ],
  36. name=基本墙,
  37. type=family
  38. ],
  39. name=墙,
  40. type=category
  41. ],
  42. name=标高 ,
  43. type=floor
  44. ],
  45. name=未设专业,
  46. type=specialty
  47. ],
  48. name=未设系统类型,
  49. type=systemType
  50. ],
  51. name=未设单体,
  52. type=building
  53. ]
  54. ]

界面上的筛选树的层次是过滤条件,主要用于筛选 type 属性。

测试代码如下:

  1. // 获取构件分类树(自定义)
  2. protected void btnGetSingleModelTreeByCustomized_Click(object sender, EventArgs e)
  3. {
  4. long fileId = txtFileID.Text.Trim().ToLong();
  5.  
  6. List<string> lstDesiredHierarchy = new List<string>();
  7. if (chkTreeBuilding.Checked)
  8. {
  9. lstDesiredHierarchy.Add("building");
  10. }
  11. if (chkTreeSystemType.Checked)
  12. {
  13. lstDesiredHierarchy.Add("systemType");
  14. }
  15. if (chkTreeSpecialty.Checked)
  16. {
  17. lstDesiredHierarchy.Add("specialty");
  18. }
  19. if (chkTreeFloor.Checked)
  20. {
  21. lstDesiredHierarchy.Add("floor");
  22. }
  23. if (chkTreeCategory.Checked)
  24. {
  25. lstDesiredHierarchy.Add("category");
  26. }
  27. if (chkTreeFamily.Checked)
  28. {
  29. lstDesiredHierarchy.Add("family");
  30. }
  31. if (chkTreeFamilyType.Checked)
  32. {
  33. lstDesiredHierarchy.Add("familyType");
  34. }
  35.  
  36. FileTreeRequestBody request = new FileTreeRequestBody();
  37. request.DesiredHierarchy = lstDesiredHierarchy.ToArray();// new[] { "building", "systemType", "specialty", "floor", "category", "family", "familyType" };
  38. request.CustomizedNodeKeys = new Dictionary<string, string> { { "category", "name" } };
  39.  
  40. FileConvertApi api = new FileConvertApi();
  41. SingleModelTreeByCustomized response = api.GetSingleModelTreeByCustomized(txtAccessToken.Text, fileId, "2.0", request);
  42.  
  43. txtResult.Text = response.Code.ToString2()
  44. + Environment.NewLine
  45. + response.Message.ToString2()
  46. + Environment.NewLine
  47. + response.Data;
  48. }
 

C#开发BIMFACE系列27 服务端API之获取模型数据12:获取构件分类树的更多相关文章

  1. C#开发BIMFACE系列45 服务端API之创建离线数据包

    BIMFACE二次开发系列目录     [已更新最新开发文章,点击查看详细] BIMFACE的常规应用方式有公有云与私有化部署两种方式,并且浏览模型或者图纸需要使用ViewToken,ViewToke ...

  2. C#开发BIMFACE系列46 服务端API之离线数据包下载及结构详解

    BIMFACE二次开发系列目录     [已更新最新开发文章,点击查看详细] 在前一篇博客<C#开发BIMFACE系列45 服务端API之创建离线数据包>中通过调用接口成功的创建一个离线数 ...

  3. C#开发BIMFACE系列30 服务端API之模型对比1:发起模型对比

    系列目录     [已更新最新开发文章,点击查看详细] 在实际项目中,由于需求变更经常需要对模型文件进行修改.为了便于用户了解模型在修改前后发生的变化,BIMFACE提供了模型在线对比功能,可以利用在 ...

  4. C#开发BIMFACE系列31 服务端API之模型对比2:获取模型对比状态

    系列目录     [已更新最新开发文章,点击查看详细] 在上一篇<C#开发BIMFACE系列30 服务端API之模型对比1:发起模型对比>中发起了2个模型对比,由于模型对比是在BIMFAC ...

  5. C#开发BIMFACE系列32 服务端API之模型对比3:批量获取模型对比状态

    系列目录     [已更新最新开发文章,点击查看详细] 在<C#开发BIMFACE系列31 服务端API之模型对比2:获取模型对比状态>中介绍了根据对比ID,获取一笔记录的对比状态.由于模 ...

  6. C#开发BIMFACE系列40 服务端API之模型集成

    BIMFACE二次开发系列目录     [已更新最新开发文章,点击查看详细] 随着建筑信息化模型技术的发展,越来越多的人选择在云端浏览建筑模型.现阶段的云端模型浏览大多是基于文件级别,一次只可以浏览一 ...

  7. C#开发BIMFACE系列41 服务端API之模型对比

    BIMFACE二次开发系列目录     [已更新最新开发文章,点击查看详细] 在建筑施工图审查系统中,设计单位提交设计完成的模型/图纸,审查专家审查模型/图纸.审查过程中如果发现不符合规范的地方,则流 ...

  8. C#开发BIMFACE系列42 服务端API之图纸对比

    BIMFACE二次开发系列目录     [已更新最新开发文章,点击查看详细] 在我的前一篇博客<C#开发BIMFACE系列42 服务端API之图纸对比>中详细介绍了BIMFACE服务端接口 ...

  9. C#开发BIMFACE系列43 服务端API之图纸拆分

    BIMFACE二次开发系列目录     [已更新最新开发文章,点击查看详细] 在上一篇博客<C#开发BIMFACE系列42 服务端API之图纸对比>的最后留了一个问题,在常规业务场景下,一 ...

随机推荐

  1. Mybatis获取代理对象

    mybatis-config.xml里标签可以放置多个environment,这里可以切换test和develop数据源 databaseIdProvider提供多种数据库,在xml映射文件里选择da ...

  2. Go中的文件读写

    在 Go 语言中,文件使用指向 os.File 类型的指针来表示的,也叫做文件句柄 .我们来看一下os包的使用方式. 1.读取文件 os包提供了两种打开文件的方法: Open(name string) ...

  3. 使用webstorm调试node.js

    折腾半天,还是webstorm顺手,但也遇到一些小问题. 1.代码补全问题 nodeJS自身的补全 File->Project Setting->JavaScript->Librar ...

  4. java集合类的相关转换

    下面的的案例,基本上是以代码为主,文字的描述较少,后期有时间会继续添加. ArrayToList public void ArrayToList() { System.out.println(&quo ...

  5. 算法之《图》Java实现

    数据结构之图 定义(百度百科) 图的术语表 无向图 深度优先搜索 广度优先遍历 有向图 路径问题 调度问题 强连通性 最小生成树(无向图) 最小生成树的贪心算法 加权无向图的数据结构 Kruskal算 ...

  6. 虚拟机安装CentOS的简短教程

    说明: 为什么要学Linux?因为现在互联网产品普遍使用Linux作为服务器系统. 测试工程师要学Linux吗?要,因为你会需要跟服务器打交道. 什么情况下测试工程师会跟服务器打交道?你可能要去部署测 ...

  7. Oracle delete和truncate实践操作之一

    实践说明 本文章主要记录在Oracle中,delete和truncate进行数据删除之后,如何进行数据恢复.由于网上对delete和truncate的区别说明较多,此处不过多介绍两者区别. 注:由于环 ...

  8. 《机器学习技法》---核型SVM

    (本文内容和图片来自林轩田老师<机器学习技法>) 1. 核技巧引入 如果要用SVM来做非线性的分类,我们采用的方法是将原来的特征空间映射到另一个更高维的空间,在这个更高维的空间做线性的SV ...

  9. ASP.NET CORE 2.* 利用集成测试框架覆盖HttpClient相关代码

    ASP.NET CORE 集成测试官方介绍 我的asp.net core 项目里面大部分功能都是去调用别人的API ,大量使用HttpClient,公司单元测试覆盖率要求95%以上,很难做到不mock ...

  10. C# 复制Excel单元格格式

    本文将介绍通过C# 复制Excel单元格格式的方法,包括复制单元格中的字体.字号.字体加粗.倾斜.单元格背景色.字体颜色.单元格数字格式.单元格文字方向.文字旋转.下划线.单元格对齐方式.单元格边框等 ...