BIMFACE二次开发
BIMFACE二次开发系列目录 【已更新最新开发文章,点击查看详细】
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZwpmL0gTOyYzN0YDOtIDOykzM0ITMyMDM2ATMyAjMtUzNyIDNx8CX2ATMyAjMvwVN3IjM0EzLcd2bsJ2Lc12bj5ycn9Gbi52YuAjMwIzZtl2Lc9CX6MHc0RHaiojIsJye.jpg)
一个楼层中可能包含多个面积分区,本文介绍如何获取楼层对应面积分区列表。
请求地址:GET https://api.bimface.com/data/v2/files/{fileId}/areas
说明:获取单个模型中单个楼层对应的分区列表。
参数:
请求 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" : "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" : 28802.013920728663,
"properties" : [ {
"group" : "dimension",
"items" : [ {
"code" : "perimeter",
"extension" : "object",
"key" : "perimeter",
"orderNumber" : 0,
"unit" : "mm",
"value" : 17200,
"valueType" : 2
} ]
} ],
"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 > 0)
{
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#实现方法:
1 /// <summary>
2 /// 获取单个模型中单个楼层对应面积分区列表
3 /// </summary>
4 /// <param name="accessToken">【必填】令牌</param>
5 /// <param name="fileId">【必填】代表该单模型的文件ID</param>
6 /// <param name="floorId">【必填】代表该单模型的楼层ID</param>
7 /// <returns></returns>
8 public virtual SingleModelSingleFloorAreas GetSingleModelSingleFloorAreas(string accessToken, long fileId, string floorId)
9 {
10 // GET https://api.bimface.com/data/v2/files/{fileId}/areas
11 string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/areas?floorId={1}", fileId, floorId);
12
13 BimFaceHttpHeaders headers = new BimFaceHttpHeaders();
14 headers.AddOAuth2Header(accessToken);
15
16 try
17 {
18 SingleModelSingleFloorAreas 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<SingleModelSingleFloorAreas>();
25 }
26 else
27 {
28 response = new SingleModelSingleFloorAreas
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系列》
测试
在BIMFACE的控制台中可以看到我们上传的文件列表,模型状态均为转换成功。
使用“bimface_2018_mdv_room.rvt”为例测试上述方法。
在《C#开发BIMFACE系列22 服务端API之获取模型数据7:获取多个模型的楼层信息》中可以查询到该文件的楼层信息
下面查询 FloorID 等于 245423 的面积分区列表
查询到的完整的面积分区列表为
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=1092832,
levelId=,
maxPt=[x=6616.83125243813, y=650.405995369963, z=2999.99987985205],
minPt=[x=4121.93135235709, y=-1145.59393270145, z=2999.99987985205],
name=面积 2, 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=1092841,
levelId=,
maxPt=[x=7001.93123701507, y=-1465.59391988567, z=2999.99987985205],
minPt=[x=4505.64541846753, y=-3302.59384631491, z=2999.99987985205],
name=面积 3,
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();
}
成在管理,败在经验;嬴在选择,输在不学! 贵在坚持!
欢迎关注作者头条号 张传宁IT讲堂,获取更多IT文章、视频等优质内容。
个人作品
1、BIMFace.Community.SDK.NET开源地址:https://gitee.com/NAlps/BIMFace.SDK
系列博客:https://www.cnblogs.com/SavionZhang/p/11424431.html
系列视频:https://www.cnblogs.com/SavionZhang/p/14258393.html
2、ZCN.NET.Common开源地址:https://gitee.com/NAlps/zcn.net.common
技术栈
1、Visual Studio、.C#/.NET、.NET Core、MVC、Web API、RESTful API、gRPC、SignalR、Python
2、jQuery、Vue.js、Bootstrap
3、数据库:SQLServer、MySQL、PostgreSQL、Oracle、SQLite、Redis、MongoDB、ElasticSearch、TiDB、达梦DM、人大金仓、 神通、南大通用 GBase、华为 GaussDB 、腾讯 TDSQL 、阿里 PolarDB、蚂蚁金服 OceanBase、东软 OpenBASE、浪潮云溪数据库 ZNBase
4、ORM:Dapper、Entity Framework、FreeSql、SqlSugar、分库分表、读写分离
5、架构:领域驱动设计 DDD、ABP
6、环境:跨平台、Windows、Linux(CentOS、麒麟、统信UOS、深度Linux)、maxOS、IIS、Nginx、Apach
7、移动App:Android、IOS、HarmonyOS、微信、小程序、快应用、Xamarin、uni-app、MUI、Flutter、Framework7、Cordova、Ionic、React Native、Taro、NutUI、Smobiler
云原生、微服务、Docker、CI/CD、DevOps、K8S;
Dapr、RabbitMQ、Kafka、分布式、大数据、高并发、负载均衡、中间件、RPC、ELK;
.NET + Docker + jenkins + Github + Harbor + K8S;
出处:www.cnblogs.com/SavionZhang
作者:张传宁 微软MCP、系统架构设计师、系统集成项目管理工程师、科技部创新工程师。
专注于微软.NET技术(.NET Core、Web、MVC、WinForm、WPF)、通用权限管理系统、工作流引擎、自动化项目(代码)生成器、SOA 、DDD、 云原生(Docker、微服务、DevOps、CI/CD);PDF、CAD、BIM 审图等研究与应用。
多次参与电子政务、图书教育、生产制造等企业级大型项目研发与管理工作。
熟悉中小企业软件开发过程:需求分析、架构设计、编码测试、实施部署、项目管理。通过技术与管理帮助中小企业快速化实现互联网技术全流程解决方案。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
如有问题,可以通过邮件[email protected]联系。共同交流、互相学习。
如果您觉得文章对您有帮助,请点击文章右下角【推荐】。您的鼓励是作者持续创作的最大动力!