一个三维模型中可能包含对应多张二维图纸列表,本篇主要介绍如何获取模型文件对应的图纸列表。
请求地址:GET https://api.bimface.com/data/v2/files/{fileId}/drawingsheets
说明:获取单个模型文件对应的图纸列表。如果请求参数elementId为null,返回所有图纸,否则返回包含该构件的所有图纸。
参数:
请求 path(示例):https://api.bimface.com/data/v2/files/1211223382064960/drawingsheets
请求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"
HTTP响应示例(200):
{ "code" : "success", "data" : [ { "fileId" : 0, "portsAndViews" : [ { "elevation" : 0.0, "outline" : [ 0.0 ], "viewId" : "6278f2c7786043d4a35ae4115571b7c8", "viewPoint" : { "origin" : [ 0.0 ], "rightDirection" : [ 0.0 ], "scale" : 0, "upDirection" : [ 0.0 ], "viewDirection" : [ 0.0 ] }, "viewType" : "viewType", "viewport" : [ 0.0 ] } ], "viewInfo" : { "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# 类,SingleModelDrawingSheets
////// 获取单个模型的图纸列表返回的结果类 /// [Serializable] public class SingleModelDrawingSheets : GeneralResponse > { }
引用的 DrawingSheet 类
////// 图纸信息类 /// [Serializable] public class DrawingSheet { /// /// 文件ID /// [JsonProperty("fileId")] public long? FileId { get; set; } /// /// 样例 : [ 0.0 ] /// [JsonProperty("portsAndViews")] public PortAndView[] PortAndViews { get; set; } [JsonProperty("viewInfo")] public ViewInfo ViewInfo { get; set; } /// 返回表示当前对象的字符串。 /// 表示当前对象的字符串。 public override string ToString() { return String.Format("[fileId={0}, portAndViews={1}, viewInfo={2}]", FileId, PortAndViews.ToStringLine(), ViewInfo); } }
引用的 PortAndView 类
[Serializable] public class PortAndView { ////// 样例 : 0.0 /// [JsonProperty("elevation")] public double? Elevation { get; set; } /// /// 样例 : [ 0.0 ] /// [JsonProperty("outline")] public double?[] Outline { get; set; } /// /// 样例 : "6278f2c7786043d4a35ae4115571b7c8" /// [JsonProperty("viewId")] public string ViewId { get; set; } [JsonProperty("viewPoint")] public ViewPoint ViewPoint { get; set; } /// /// 样例 : "viewType" /// [JsonProperty("viewType")] public string ViewType { get; set; } /// /// 样例 : [ 0.0 ] /// [JsonProperty("viewport")] public double?[] Viewport { get; set; } /// 返回表示当前对象的字符串。 /// 表示当前对象的字符串。 public override string ToString() { return String.Format("[elevation={0}, outline={1}, viewId={2}, viewPoint={3}, viewType={4}, viewport={5}]", Elevation, Outline.ToStringWith(","), ViewId, ViewPoint, ViewType, Viewport.ToStringWith(",")); } }
引用的 ViewPoint 类
[Serializable] public class ViewPoint { ////// 样例 : [ 0.0 ] /// [JsonProperty("origin")] public double?[] Origin { get; set; } /// /// 样例 : [ 0.0 ] /// [JsonProperty("rightDirection")] public double?[] RightDirection { get; set; } /// /// 样例 : [ 0.0 ] /// [JsonProperty("scale")] public int? Scale { get; set; } /// /// 样例 : [ 0.0 ] /// [JsonProperty("upDirection")] public double?[] UpDirection { get; set; } /// /// 样例 : [ 0.0 ] /// [JsonProperty("viewDirection")] public double?[] ViewDirection { get; set; } /// 返回表示当前对象的字符串。 /// 表示当前对象的字符串。 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 ///2 /// 获取单个模型的图纸列表。 3 /// 如果请求参数elementId为null,返回所有图纸,否则返回包含该构件的所有图纸 4 /// 5 /// 【必填】令牌 6 /// 【必填】代表该单模型的文件ID 7 /// 【非必填】构件ID 8 /// 9 public virtual SingleModelDrawingSheets GetSingleModelDrawingSheets(string accessToken, long fileId, string elementId = null) 10 { 11 // GET https://api.bimface.com/data/v2/files/{fileId}/drawingsheets 12 string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/files/{0}/drawingsheets", fileId); 13 if (!string.IsNullOrWhiteSpace(elementId)) 14 { 15 url = url + "?elementId=" + elementId; 16 } 17 18 BimFaceHttpHeaders headers = new BimFaceHttpHeaders(); 19 headers.AddOAuth2Header(accessToken); 20 21 try 22 { 23 SingleModelDrawingSheets response; 24 25 HttpManager httpManager = new HttpManager(headers); 26 HttpResult httpResult = httpManager.Get(url); 27 if (httpResult.Status == HttpResult.STATUS_SUCCESS) 28 { 29 response = httpResult.Text.DeserializeJsonToObject (); 30 } 31 else 32 { 33 response = new SingleModelDrawingSheets 34 { 35 Message = httpResult.RefText 36 }; 37 } 38 39 return response; 40 } 41 catch (Exception ex) 42 { 43 throw new Exception("[获取图纸列表]发生异常!", ex); 44 } 45 }
在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=[height=, path=, width=], 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=[height=, path=, width=], 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=[height=, path=, width=], viewType=DrawingSheet ] ]
测试代码如下:
// 获取图纸列表 protected void btnGetSingleModelDrawingSheets_Click(object sender, EventArgs e) { long fileId = txtFileID.Text.Trim().ToLong(); string elementId = txtElementId.Text.Trim(); FileConvertApi api = new FileConvertApi(); SingleModelDrawingSheets response = api.GetSingleModelDrawingSheets(txtAccessToken.Text, fileId, elementId); txtResult.Text = response.Code.ToString2() + Environment.NewLine + response.Message.ToString2() + Environment.NewLine + response.Data.ToStringLine(); }
我的博客即将同步至腾讯云+社区,邀请大家一同入驻:
https://cloud.tencent.com/developer/support-plan?invite_code=1e6h2qd3iny51