系列目录 【已更新最新开发文章,点击查看详细】 在代表模型的源文件上传到BIMFACE后,一般会进行三种API调用操作: 发起模型转换 查询转换状态 如转换成功,获取模型转换后的BIM数据 在模型成功进行转换后,模型内的BIM信息会在云端进行解析,抽取并结构化入库。这些信息包含: 构件属性信息 构件分类树 楼层 单体 专业 构件材质 模型链接 空间 房间 图纸 …​ 在确认模型转换成功后,为了开发者能方便的获取这些BIM信息并集成在自己的应用中,BIMFACE提供了一系列的数据接口,这些接口支持两种验权方式: Access token: 代表自身应用的身份,使用应用的appkey, secret,通过调用/oauth2/token接口获取。 View token: 代表对单个模型的访问权限,使用access token,通过调用/view/token以及相关接口获得。 发起转换 请求地址:PUT https://api.bimface.com/translate 说明:源文件上传成功后,即可发起对该文件的转换。由于转换不能立即完成,BIMFace支持在文件转换完成以后,通过Callback机制通知应用;另外,应用也可以通过接口查询转换状态。 参数:application/json 格式 请求 path(示例):https://api.bimface.com/translate 请求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b" 请求 body(示例): 复制代码 { "callback" : "https://api.glodon.com/viewing/callback?authCode=iklJk0affae&signature=2ef131395fb6442eb99abd83d45c3201", "config" : { "string" : "string" }, "priority" : 2, "source" : { "compressed" : false, "fileId" : 1277823232112, "rootName" : "rootFileName.rvt" } } 复制代码 注意:请求体中的 config 可以设置为空。"config":null 或者传入指定的转换参数 "config":{"texture":true} 。 HTTP响应示例(200): 复制代码 { "code" : "success", "data" : { "createTime" : "2017-12-25 17:23:46", "databagId" : "9b711803a43b92d871cde346b63e5019", "fileId" : 1248789071339712, "name" : "bimface_2018.rvt", "priority" : 2, "reason" : "reason", "status" : "success", "thumbnail" : [ "https://m.bimface.com/9b711803a43b92d871cde346b63e5019/thumbnail/96.png", "https://m.bimface.com/9b711803a43b92d871cde346b63e5019/thumbnail/256.png" ] }, "message" : "" } 复制代码 请求体内的参数解释 DGW与RVT格式的文件转换的配置参数不同,所以封装了2个对应的C#类: 复制代码 1 /// 2 /// 发起DWG文件转化的请求数据 3 /// 4 [Serializable] 5 public class DwgFileTranslateRequest : FileTranslateRequest 6 { 7 /// 8 /// Dwg模型转换引擎自定义参数,config参数跟转换引擎相关,不同的转换引擎支持不同的config格式。 9 /// 例如转换时添加内置材质,则添加参数值{"texture":true},添加外部材质时参考“使用模型外置材质场景”请求报文。 10 /// 如果不需要设置该参数,则设置为null 11 /// 12 [JsonProperty("config", NullValueHandling = NullValueHandling.Ignore)] 13 public DwgModelConfig Config { get; set; } 14 } 复制代码 复制代码 1 /// 2 /// 发起Rvt文件转化的请求数据 3 /// 4 [Serializable] 5 public class RvtFileTranslateRequest : FileTranslateRequest 6 { 7 /// 8 /// Rvt模型转换引擎自定义参数,config参数跟转换引擎相关,不同的转换引擎支持不同的config格式。 9 /// 例如转换时添加内置材质,则添加参数值{"texture":true},添加外部材质时参考“使用模型外置材质场景”请求报文。 10 /// 如果不需要设置该参数,则设置为null 11 /// 12 [JsonProperty("config", NullValueHandling = NullValueHandling.Ignore)] 13 public RvtModelConfig Config { get; set; } 14 } 复制代码 复制代码 1 /// 2 /// 其他三维模型文件,包括RVT格式文转化的请求数据 3 /// 4 [Serializable] 5 public class Other3DModelFileTranslateRequest : RvtFileTranslateRequest 6 { 7 } 复制代码 复制代码 1 [Serializable] 2 public class TranslateSource 3 { 4 public TranslateSource() 5 { 6 Compressed = false; 7 RootName = null; 8 } 9 10 /// 11 /// 文件Id,即调用上传文件API返回的fileId 12 /// 13 [JsonProperty("fileId")] 14 public long FileId { get; set; } 15 16 /// 17 /// 是否为压缩文件,默认为false 18 /// 19 [JsonProperty("compressed")] 20 public bool Compressed { get; set; } 21 22 /// 23 /// 如果是压缩文件,必须指定压缩包中哪一个是主文件。(例如:root.rvt)。 24 /// 如果不是压缩,则设置为 null 25 /// 26 [JsonProperty("rootName", NullValueHandling = NullValueHandling.Ignore)] 27 public string RootName { get; set; } 28 } 复制代码 共同的基类FileTranslateRequest: 复制代码 1 /// 2 /// 发起文件转化的请求数据 3 /// 4 [Serializable] 5 public class FileTranslateRequest 6 { 7 public FileTranslateRequest() 8 { 9 Priority = 2; 10 CallBack = "http://www.app.com/receive"; 11 } 12 13 [JsonProperty("source")] 14 public TranslateSource Source { get; set; } 15 16 /// 17 /// 优先级,数字越大,优先级越低。只能是1, 2, 3。默认为2 18 /// 19 [JsonProperty("priority")] 20 public int Priority { get; set; } 21 22 /// 23 /// Callback地址,待转换完毕以后,BIMFace会回调该地址 24 /// 25 [JsonProperty("callback")] 26 public string CallBack { get; set; } 27 } 复制代码 不同模型转换支持的自定义参数config: (1) rvt模型 对应封装成的C#实体类: 复制代码 1 /// 2 /// rvt 模型配置项 3 /// 4 [Serializable] 5 public class RvtModelConfig 6 { 7 public RvtModelConfig() 8 { 9 //设置 null,在序列化的时候忽略该字段,不出现在序列化后的字符串中 10 Texture = null; 11 ExportDwg = null; 12 ExportDrawing = null; 13 ExportPdf = null; 14 ViewName = null; 15 DisplayLevel = null; 16 ExportDwgInstance = null; 17 ExportHiddenObjects = null; 18 ExportSystemType = null; 19 ExportProperties = null; 20 Unit = null; 21 ExportSchedule = null; 22 } 23 24 /// 25 /// 转换时是否添加材质。默认为 false 26 /// 27 [JsonProperty("texture", NullValueHandling = NullValueHandling.Ignore)] 28 public bool? Texture { get; set; } 29 30 /// 31 /// rvt2md是否导出dwg文件。默认为 false 32 /// 33 [JsonProperty("exportDwg", NullValueHandling = NullValueHandling.Ignore)] 34 public bool? ExportDwg { get; set; } 35 36 /// 37 /// dwg2md是否导出mdv(矢量化图纸);取值为true时,exportDwg自动设置为true。默认为 false 38 /// 39 [JsonProperty("exportDrawing", NullValueHandling = NullValueHandling.Ignore)] 40 public bool? ExportDrawing { get; set; } 41 42 /// 43 /// dwg2md是否导出pdf文件。默认为 false 44 /// 45 [JsonProperty("exportPdf", NullValueHandling = NullValueHandling.Ignore)] 46 public bool? ExportPdf { get; set; } 47 48 /// 49 /// 转换使用的3D视图。默认为 {3D} 50 /// 51 [JsonProperty("viewName", NullValueHandling = NullValueHandling.Ignore)] 52 public string ViewName { get; set; } 53 54 /// 55 /// 设置转换的精细度,fine(精细),medium(中等),coarse(粗略)。默认为 fine 56 /// 57 [JsonProperty("displaylevel", NullValueHandling = NullValueHandling.Ignore)] 58 public string DisplayLevel { get; set; } 59 60 /// 61 /// 是否导出dwg实例。默认为 false 62 /// 63 [JsonProperty("exportDwgInstance", NullValueHandling = NullValueHandling.Ignore)] 64 public bool? ExportDwgInstance { get; set; } 65 66 /// 67 /// 是否导出三维视图中隐藏的构件。默认为 false 68 /// 69 [JsonProperty("exportHiddenObjects", NullValueHandling = NullValueHandling.Ignore)] 70 public bool? ExportHiddenObjects { get; set; } 71 72 /// 73 /// 是否在userData中加入mepSystemType。默认为 false 74 /// 75 [JsonProperty("exportSystemType", NullValueHandling = NullValueHandling.Ignore)] 76 public bool? ExportSystemType { get; set; } 77 78 /// 79 /// 是否在导出NWD的属性db文件。默认为 false 80 /// 81 [JsonProperty("exportProperties", NullValueHandling = NullValueHandling.Ignore)] 82 public bool? ExportProperties { get; set; } 83 84 /// 85 /// 设置转换使用的单位,取值"ft"\"feet"\"英尺"采用revit默认的英尺为单位,默认以毫米为单位。默认为空 86 /// 87 [JsonProperty("unit", NullValueHandling = NullValueHandling.Ignore)] 88 public string Unit { get; set; } 89 90 /// 91 /// 是否使用明细表内容。默认为 false 92 /// 93 [JsonProperty("exportSchedule", NullValueHandling = NullValueHandling.Ignore)] 94 public bool? ExportSchedule { get; set; } 95 } 复制代码 Rvt转换配置中很多选项都是有默认值的,如果手动设置的值与默认值相同,那么可以不用设置该项。 为了简化显示请求body中的config配置项,在构造函数中将数值类型的配置项默认设置为 null,再配合 Newtonsoft.Json.dll [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] 属性,在序列化时可以不生成该项。 (2) dwg模型 对应封装成的C#实体类 复制代码 1 /// 2 /// dwg 模型配置项 3 /// 4 [Serializable] 5 public class DwgModelConfig 6 { 7 /// 8 /// 是否转成矢量图纸,默认为 true 9 /// 10 [JsonProperty("exportDrawing")] 11 public bool ExportDrawing { get; set; } 12 13 /// 14 /// 是否导出pdf文件,默认为 false 15 /// 16 [JsonProperty("exportPdf")] 17 public bool ExportPdf { get; set; } 18 19 /// 20 /// 是否导出缩略图,默认为 true 21 /// 22 [JsonProperty("exportThumb")] 23 public bool ExportThumb { get; set; } 24 } 复制代码 下面分别介绍常用的不同类型的文件转换场景 1、DWG文件转换成矢量图纸 请求 body(示例): 复制代码 { "source":{ "fileId":1402934652281952, // 文件ID "compressed":false // 文件是否为压缩文件 }, "priority":2, // 转换优先级 "callback":"http://www.app.com/receive", // 回调地址 "config":null // 转换配置选项 } 复制代码 C#实现方法: 复制代码 1 /// 2 /// 发起转换。将DWG文件转换成图片。 3 /// 4 /// 令牌 5 /// DWG文件转化的请求数据对象。根据实际需要设置对象里面的参数,不需要的参数不用赋值 6 /// 7 public virtual FileTranslateResponse TranslateDwgToPicture(string accessToken, DwgFileTranslateRequest request) 8 { 9 string data = request.SerializeToJson(); 10 return TranslateFile(accessToken, data); 11 } 复制代码 其中调用的 TranslateFile()方法如下: 复制代码 1 /// 2 /// 发起转换。 3 /// 源文件上传成功后,即可发起对该文件的转换。由于转换不能立即完成,BIMFace支持在文件转换完成以后,通过Callback机制通知应用; 4 /// 另外,应用也可以通过接口查询转换状态 5 /// 6 /// 令牌 7 /// 请求体数据 8 /// 9 private FileTranslateResponse TranslateFile(string accessToken, string data) 10 { 11 //PUT https://api.bimface.com/translate 12 string url = BimfaceConstants.API_HOST + "/translate"; 13 14 BimFaceHttpHeaders headers = new BimFaceHttpHeaders(); 15 headers.AddOAuth2Header(accessToken); 16 17 try 18 { 19 FileTranslateResponse response; 20 21 HttpManager httpManager = new HttpManager(headers); 22 HttpResult httpResult = httpManager.Put(url, data); 23 if (httpResult.Status == HttpResult.STATUS_SUCCESS) 24 { 25 response = httpResult.Text.DeserializeJsonToObject(); 26 } 27 else 28 { 29 response = new FileTranslateResponse 30 { 31 Message = httpResult.RefText 32 }; 33 } 34 35 return response; 36 } 37 catch (Exception ex) 38 { 39 throw new Exception("[发起文件转换]发生异常!", ex); 40 } 41 } 复制代码 该方法在后面的几种模型转换中也会用到,是公用的方法。 其中调用到的 httpManager.Put() 方法,请参考《C# HTTP系列》 2、DWG文件转换成图片 请求 body(示例): 复制代码 { "source":{ "fileId":857482189666208, "compressed":false, "rootName":"root.dwg" }, "priority":2, "callback":"http://www.app.com/receive", "config":{ "exportDrawing":false // 是否转成矢量图纸 } } 复制代码 C#实现方法: 复制代码 1 /// 2 /// 发起转换。将DWG文件转换成图片。 3 /// 4 /// 令牌 5 /// DWG文件转化的请求数据对象。根据实际需要设置对象里面的参数,不需要的参数不用赋值 6 /// 7 public virtual FileTranslateResponse TranslateDwgToPicture(string accessToken, DwgFileTranslateRequest request) 8 { 9 string data = request.SerializeToJson(); 10 return TranslateFile(accessToken, data); 11 } 复制代码 3、RVT文件转换成着色模式的效果 请求 body(示例): 复制代码 { "source":{ "fileId":857482189666208, "compressed":false, "rootName":"root.rvt" // 如果是压缩文件,必须指定压缩包中哪一个是主文件 }, "priority":2, "callback":"http://www.app.com/receive", "config":null } 复制代码 C#实现方法: 复制代码 1 /// 2 /// 发起转换。将RVT文件转换成着色模式的效果。 3 /// 4 /// 令牌 5 /// RVT文件转化的请求数据对象。根据实际需要设置对象里面的参数,不需要的参数不用赋值 6 /// 7 public virtual FileTranslateResponse TranslateRvtToRenderStyle(string accessToken, RvtFileTranslateRequest request) 8 { 9 string data = request.SerializeToJson(); 10 return TranslateFile(accessToken, data); 11 } 复制代码 4、RVT文件转换成真实模式的效果 请求 body(示例): 复制代码 { "source":{ "fileId":857482189666208, "compressed":false, "rootName":"root.rvt" }, "priority":2, "callback":"http://www.app.com/receive", "config":{"texture":true} // 转换时是否添加材质 } 复制代码 C#实现方法: 复制代码 1 /// 2 /// 发起转换。将RVT文件转换成真实模式的效果。 3 /// 4 /// 令牌 5 /// RVT文件转化的请求数据对象。根据实际需要设置对象里面的参数,不需要的参数不用赋值 6 /// 7 public virtual FileTranslateResponse TranslateRvtToRealStyle(string accessToken, RvtFileTranslateRequest request) 8 { 9 string data = request.SerializeToJson(); 10 return TranslateFile(accessToken, data); 11 } 复制代码 5、RVT格式文件转换成具备二三维联动的功能 请求 body(示例): 复制代码 { "source":{ "fileId":1402934652281952, "compressed":false }, "priority":2, "config":{ "texture": false, // 转换时是否添加材质 "exportDwg": true, // rvt2md是否导出dwg文件 "exportPdf": true, // dwg2md是否导出pdf文件 "exportDrawing": true // dwg2md是否导出mdv(矢量化图纸);取值为true时,exportDwg自动设置为true }, "callback":"http://www.app.com/receive" } 复制代码 C#实现方法: 复制代码 1 /// 2 /// 发起转换。将RVT格式文件转换为具备二三维联动的功能效果。 3