C#开发BIMFACE系列28 服务端API之获取模型数据13:获取三维视点或二维视图列表
本篇主要介绍如何获取一个模型中包含的三维视点或二维视图列表。
请求地址:GET https://api.bimface.com/data/v2/files/{fileId}/views
说明:获取单模型中包含的三维视点或二维视图列表。
参数:
请求 path(示例):https://api.bimface.com/data/v2/files/1211223382064960/views
请求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"
HTTP响应示例(200):
{ "code" : "success", "data" : [ { "cropBox" : [ -12147.804809235151, -19279.554054815613, -30480.0, 22637.545576143948, 6805.089759789783, 30480.0 ], "elevation" : 0.0, "id" : "312", "levelId" : "312", "name" : "Level 1", "outline" : [ -146.52900292249365, -215.01048476685295, 240.3331231070219, 110.78415780710446 ], "preview" : { "height" : 0, "path" : "path", "width" : 0 }, "thumbnails" : [ "m.bimface.com/9b711803a43b92d871cde346b63e5019/resource/thumbnails/312/312.96x96.png" ], "viewPoint" : { "origin" : [ 0.0 ], "rightDirection" : [ 0.0 ], "scale" : 0, "upDirection" : [ 0.0 ], "viewDirection" : [ 0.0 ] }, "viewType" : "FloorPlain" } ], "message" : "" }
该返回结果的结构比较复杂,封装成如下的C#类
/// <summary> /// 获取三维视点或二维视图列表的返回结果类 /// </summary> [Serializable] public class SingleModelViews : GeneralResponse<List<ViewInfo>> { }
引用的 ViewInfo 类
/// <summary> /// 三维视点或二维视图 /// </summary> [Serializable] public class ViewInfo { /// <summary> /// 样例:[ -12147.804809235151, -19279.554054815613, -30480.0, 22637.545576143948, 6805.089759789783, 30480.0 ] /// </summary> [JsonProperty("cropBox")] public double?[] CropBox { get; set; } /// <summary> /// 样例:0.0 /// </summary> [JsonProperty("elevation")] public double? Elevation { get; set; } /// <summary> /// 样例:"312" /// </summary> [JsonProperty("id")] public string Id { get; set; } /// <summary> /// 样例:"312" /// </summary> [JsonProperty("levelId")] public string LevelId { get; set; } /// <summary> /// 样例:[ -146.52900292249365, -215.01048476685295, 240.3331231070219, 110.78415780710446 ] /// </summary> [JsonProperty("outline")] public double?[] Outline { get; set; } [JsonProperty("preview")] public Preview Preview { get; set; } /// <summary> /// 缩略图数组。样例:[ "m.bimface.com/9b711803a43b92d871cde346b63e5019/resource/thumbnails/312/312.96x96.png" ] /// </summary> [JsonProperty("thumbnails")] public string[] Thumbnails { get; set; } [JsonProperty("viewPoint")] public ViewPoint ViewPoint { get; set; } [JsonProperty("viewType")] public string ViewType { get; set; } /// <summary>返回表示当前对象的字符串。</summary> /// <returns>表示当前对象的字符串。</returns> public override string ToString() { return string.Format("[cropBox={0}, elevation={1}, width={2}, Id={2}, levelId={3}, Outline={4}, preview={5}, thumbnails={6}, viewPoint={7}, viewType={8}]", CropBox.ToStringWith(","), Elevation, Id, LevelId, Outline.ToStringWith(","), Preview, Thumbnails.ToStringWith(","), ViewPoint, ViewType); } }
其中引用的 Preview 类
[Serializable] public class Preview { /// <summary> /// 样例:0 /// </summary> [JsonProperty("height")] public int? Height { get; set; } [JsonProperty("path")] public string Path { get; set; } /// <summary> /// 样例:0 /// </summary> [JsonProperty("width")] public int? Width { get; set; } /// <summary>返回表示当前对象的字符串。</summary> /// <returns>表示当前对象的字符串。</returns> public override string ToString() { return string.Format("[height={0}, path={1}, width={2}]", Height, Path, Width); } }
ViewPoint 类
[Serializable] public class ViewPoint { /// <summary> /// 样例 : [ 0.0 ] /// </summary> [JsonProperty("origin")] public double?[] Origin { get; set; } /// <summary> /// 样例 : [ 0.0 ] /// </summary> [JsonProperty("rightDirection")] public double?[] RightDirection { get; set; } /// <summary> /// 样例 : [ 0.0 ] /// </summary> [JsonProperty("scale")] public int? Scale { get; set; } /// <summary> /// 样例 : [ 0.0 ] /// </summary> [JsonProperty("upDirection")] public double?[] UpDirection { get; set; } /// <summary> /// 样例 : [ 0.0 ] /// </summary> [JsonProperty("viewDirection")] public double?[] ViewDirection { get; set; } /// <summary>返回表示当前对象的字符串。</summary> /// <returns>表示当前对象的字符串。</returns> public override string ToString() { return String.Format("[origin={0}, rightDirection={1}, scale={2}, upDirection={3}, viewDirection={4}]", Origin.ToStringWith(","), RightDirection.ToStringWith(","), Scale, UpDirection.ToStringWith(","), ViewDirection.ToStringWith(",")); } }
C#实现方法:
1 /// <summary> 2 /// 获取三维视点或二维视图列表 3 /// </summary> 4 /// <param name="accessToken">【必填】令牌</param> 5 /// <param name="fileId">【必填】代表该单模型的文件ID</param> 6 /// <returns></returns> 7 public virtual SingleModelViews GetSingleModelViews(string accessToken, long fileId) 8 { 9 // GET https://api.bimface.com/data/v2/files/{fileId}/views 10 string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/views", fileId); 11 12 BimFaceHttpHeaders headers = new BimFaceHttpHeaders(); 13 headers.AddOAuth2Header(accessToken); 14 15 try 16 { 17 SingleModelViews response; 18 19 HttpManager httpManager = new HttpManager(headers); 20 HttpResult httpResult = httpManager.Get(url); 21 if (httpResult.Status == HttpResult.STATUS_SUCCESS) 22 { 23 response = httpResult.Text.DeserializeJsonToObject<SingleModelViews>(); 24 } 25 else 26 { 27 response = new SingleModelViews 28 { 29 Message = httpResult.RefText 30 }; 31 } 32 33 return response; 34 } 35 catch (Exception ex) 36 { 37 throw new Exception("[获取楼层对应面积分区列表]发生异常!", ex); 38 } 39 }
其中调用到的 httpManager.Get() 方法,请参考《C# HTTP系列》
在BIMFACE的控制台中可以看到我们上传的文件列表,模型状态均为转换成功。
使用“bimface_2018_mdv_room.rvt”为例测试上述方法。
完整的视图列表为
success [fileId=, portAndViews=, viewInfo=[cropBox=-30479.998046875,-30479.998046875,-304800,30479.998046875,30479.998046875,-30.4799995422363, elevation=0, width=382617, Id=382617, levelId=, Outline=2.49999989974552,-0.999999959964061,842.499966258321,592.999976250742, preview=[height=724, path=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/382617/382617.png, width=1024 ], thumbnails=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/382617/382617.96x96.png, viewPoint=[origin=0,0,0, rightDirection=1,0,0, scale=1, upDirection=0,1,0, viewDirection=0,0,1 ], viewType=DrawingSheet ] ] [fileId=, portAndViews=, viewInfo=[cropBox=-30479.998046875,-30479.998046875,-304800,30479.998046875,30479.998046875,-30.4799995422363, elevation=0, width=503701, Id=503701, levelId=, Outline=2.49999989974552,-0.999999959964061,842.499966258321,592.999976250742, preview=[height=724, path=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/503701/503701.png, width=1024], thumbnails=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/503701/503701.96x96.png, viewPoint=[origin=0,0,0, rightDirection=1,0,0, scale=1, upDirection=0,1,0, viewDirection=0,0,1], viewType=DrawingSheet]]
[fileId=, portAndViews=, viewInfo=[cropBox=-30479.998046875,-30479.998046875,-304800,30479.998046875,30479.998046875,-30.4799995422363, elevation=0, width=958184, Id=958184, levelId=, Outline=2.49999989974552,-0.999999959964061,842.499966258321,592.999976250742, preview=[height=724, path=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/958184/958184.png, width=1024], thumbnails=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/958184/958184.96x96.png, viewPoint=[origin=0,0,0, rightDirection=1,0,0, scale=1, upDirection=0,1,0, viewDirection=0,0,1], viewType=DrawingSheet]]
[fileId=, portAndViews=, viewInfo=[cropBox=-30479.998046875,-30479.998046875,-304800,30479.998046875,30479.998046875,-30.4799995422363, elevation=0, width=958251, Id=958251, levelId=, Outline=2.49999989974552,-0.999999959964061,842.499966258321,592.999976250742, preview=[height=724, path=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/958251/958251.png, width=1024], thumbnails=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/958251/958251.96x96.png, viewPoint=[origin=0,0,0, rightDirection=1,0,0, scale=1, upDirection=0,1,0, viewDirection=0,0,1], viewType=DrawingSheet]]
[fileId=, portAndViews=, viewInfo=[cropBox=-30479.998046875,-30479.998046875,-304800,30479.998046875,30479.998046875,-30.4799995422363, elevation=0, width=959135, Id=959135, levelId=, Outline=2.49999989974552,-0.999999959964061,842.499966258321,592.999976250742, preview=[height=724, path=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/959135/959135.png, width=1024], thumbnails=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/959135/959135.96x96.png, viewPoint=[origin=0,0,0, rightDirection=1,0,0, scale=1, upDirection=0,1,0, viewDirection=0,0,1], viewType=DrawingSheet]]
[fileId=, portAndViews=, viewInfo=[cropBox=-30479.998046875,-30479.998046875,-304800,30479.998046875,30479.998046875,-30.4799995422363, elevation=0, width=959510, Id=959510, levelId=, Outline=2.49999989974552,-73.1185993073838,842.499966258321,592.999976250742, preview=[height=812, path=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/959510/959510.png, width=1024], thumbnails=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/959510/959510.96x96.png, viewPoint=[origin=0,0,0, rightDirection=1,0,0, scale=1, upDirection=0,1,0, viewDirection=0,0,1], viewType=DrawingSheet]]
[fileId=, portAndViews=, viewInfo=[cropBox=-30479.998046875,-30479.998046875,-304800,30479.998046875,30479.998046875,-30.4799995422363, elevation=0, width=1080884, Id=1080884, levelId=, Outline=2.49999989974552,-0.999999959964061,842.499966258321,592.999976250742, preview=[height=724, path=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/1080884/1080884.png, width=1024], thumbnails=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/1080884/1080884.96x96.png, viewPoint=[origin=0,0,0, rightDirection=1,0,0, scale=1, upDirection=0,1,0, viewDirection=0,0,1], viewType=DrawingSheet]]
[fileId=, portAndViews=, viewInfo=[cropBox=-30479.998046875,-30479.998046875,-304800,30479.998046875,30479.998046875,-30.4799995422363, elevation=0, width=1081048, Id=1081048, levelId=, Outline=2.49999989974552,-0.999999959964061,842.499966258321,592.999976250742, preview=[height=724, path=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/1081048/1081048.png, width=1024], thumbnails=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/1081048/1081048.96x96.png, viewPoint=[origin=0,0,0, rightDirection=1,0,0, scale=1, upDirection=0,1,0, viewDirection=0,0,1], viewType=DrawingSheet]]
[fileId=, portAndViews=, viewInfo=[cropBox=-30479.998046875,-30479.998046875,-304800,30479.998046875,30479.998046875,-30.4799995422363, elevation=0, width=1081066, Id=1081066, levelId=, Outline=2.49999989974552,-0.999999959964061,842.499966258321,592.999976250742, preview=[height=724, path=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/1081066/1081066.png, width=1024], thumbnails=m.bimface.com/6bd2057ac6d8072ad03758b0b34e205d/resource/thumbnails/1081066/1081066.96x96.png, viewPoint=[origin=0,0,0, rightDirection=1,0,0, scale=1, upDirection=0,1,0, viewDirection=0,0,1], viewType=DrawingSheet]]
测试代码如下:
// 获取三维视点或二维视图列表 protected void btnGetSingleModelViews_Click(object sender, EventArgs e) { long fileId = txtFileID.Text.Trim().ToLong(); FileConvertApi api = new FileConvertApi(); SingleModelViews response = api.GetSingleModelViews(txtAccessToken.Text, fileId); txtResult.Text = response.Code.ToString2() + Environment.NewLine + response.Message.ToString2() + Environment.NewLine + response.Data.ToStringLine(); }
成在管理,败在经验;嬴在选择,输在不学! 贵在坚持!
个人作品
BIMFace.SDK.NET
开源地址:https://gitee.com/NAlps/BIMFace.SDK
系列博客:https://www.cnblogs.com/SavionZhang/p/11424431.html
系列视频:https://www.cnblogs.com/SavionZhang/p/14258393.html
技术栈
1、Visual Studio、.NET Core/.NET、MVC、Web API、RESTful API、gRPC、SignalR、Java、Python
2、jQuery、Vue.js、Bootstrap、ElementUI
3、数据库:分库分表、读写分离、SQLServer、MySQL、PostgreSQL、Redis、MongoDB、ElasticSearch、达梦DM
4、架构:DDD、ABP、SpringBoot、jFinal
5、环境:跨平台、Windows、Linux、Nginx
6、移动App:Android、IOS、HarmonyOS、微信小程序、钉钉、uni-app、MAUI
分布式、高并发、云原生、微服务、Docker、CI/CD、DevOps、K8S;Dapr、RabbitMQ、Kafka、RPC、Elasticsearch。
欢迎关注作者头条号 张传宁IT讲堂,获取更多IT文章、视频等优质内容。
出处:www.cnblogs.com/SavionZhang
作者:张传宁 技术顾问、培训讲师、微软MCP、系统架构设计师、系统集成项目管理工程师、科技部创新工程师。
专注于企业级通用开发平台、工作流引擎、自动化项目(代码)生成器、SOA 、DDD、 云原生(Docker、微服务、DevOps、CI/CD);PDF、CAD、BIM 审图等研究与应用。
多次参与电子政务、图书教育、生产制造等企业级大型项目研发与管理工作。
熟悉中小企业软件开发过程:可行调研、需求分析、架构设计、编码测试、实施部署、项目管理。通过技术与管理帮助中小企业实现互联网转型升级全流程解决方案。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
如有问题,可以通过邮件905442693@qq.com联系。共同交流、互相学习。
如果您觉得文章对您有帮助,请点击文章右下角【推荐】。您的鼓励是作者持续创作的最大动力!