【已更新最新开发文章,点击查看详细】
C#开发BIMFACE系列30 服务端API之模型对比1:发起模型对比

  在实际项目中,由于需求变更经常需要对模型文件进行修改。为了便于用户了解模型在修改前后发生的变化,BIMFACE提供了模型在线对比功能,可以利用在线的模型对比接口,通过简单的四个步骤实现模型在线对比。模型对比可以对两个文件/模型进行差异性分析,确定两个文件/模型之间构件的几何和属性差异,包括增加的构件、删除的构件和修改的构件。 模型对应可以用于进行文件/模型的版本对比。

特别说明:模型对比是在BIMFACE云端进行的,通常需要5~10分钟。当模型对比完成后,BIMFACE能通知对比结果。

前置条件
  • 您需要将修改前和修改后的模型上传到云端并转换成功以后才能发起模型对比;
  • 目前仅支持.rvt单文件的模型对比。
基本步骤
  1. 通过服务端API发起模型对比(对比前后模型文件的fileId);
  2. 等待云端对比任务执行;
  3. 对比完成后,在网页端通过调用JavaScript API实现差异模型的显示;
  4. 除了显示差异模型,还需要调用服务端API获取对比结果(包括新增、删除、修改的构件列表)。
对比流程

  模型文件经过云端转换后,生成了BIMFACE定义的数据包。因此,要对比两个模型文件,实际上需要对比两个文件的数据包。如下图所示,文件B是文件A修改后的版本,对比完成之后,其结果包括两个部分:

  • 几何差异;
  • 变更构件及属性。

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

发起模型对比

对比操作的第一步是调用服务端API发起模型对比。

请求地址:POST https://api.bimface.com/v2/compare

说明:不同版本的模型文件上传并转换成功后,即可发起模型对比。由于对比不能立即完成,BIMFace支持在模型对比完成以后,通过Callback机制通知应用;另外,应用也可以通过接口查询对比状态。

参数:

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

请求 path(示例):https://api.bimface.com/v2/compare

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

请求 body(示例):

{
  "callback" : "https://api.glodon.com/viewing/callback?authCode=BJ90Jk0affae&signature=2ef131395fb6442eb99abd83d45c2412",
  "comparedEntityType" : "file",
  "config" : "object",
  "followingId" : 22145522,
  "name" : "compare0001",
  "previousId" : 12311221,
  "priority" : 2,
  "sourceId" : "123223223212"
}

HTTP响应示例(200):

{
  "code" : "success",
  "data" : {
    "compareId" : 1248756572307264,
    "createTime" : "2017-12-25 16:17:27",
    "name" : "compare0001",
    "priority" : 2,
    "reason" : "reason",
    "sourceId" : "123223223212",
    "status" : "succcess",
    "thumbnail" : [ "https://m.bimface.com/9b711803a43b92d871cde346b63e5019/thumbnail/96.png" ]
  },
  "message" : ""
}

C#实现方法:

 1 /// <summary>
 2 ///  不同版本的模型文件上传并转换成功后,即可发起模型对比。由于对比不能立即完成,BIMFace支持在模型对比完成以后,通过Callback机制通知应用;另外,应用也可以通过接口查询对比状态
 3 /// </summary>
 4 /// <param name="accessToken">【必填】令牌</param>
 5 /// <param name="followingId">修改后图纸(当前本班,本轮)模型文件ID</param>
 6 /// <param name="previousId">修改前图纸(历史版本,上一轮次)模型文件ID</param>
 7 /// <returns></returns>
 8 public virtual ModelCompareResponse Compare(string accessToken, long followingId, long previousId)
 9 {
10     CompareRequest request = new CompareRequest(followingId, previousId);
11 
12     return Compare(accessToken, request);
13 }

其中12行的Compare方法调用了重载方法,实现如下:

 1 /// <summary>
 2 ///  不同版本的模型文件上传并转换成功后,即可发起模型对比。由于对比不能立即完成,BIMFace支持在模型对比完成以后,通过Callback机制通知应用;另外,应用也可以通过接口查询对比状态
 3 /// </summary>
 4 /// <param name="accessToken">【必填】令牌</param>
 5 /// <param name="request">对比时的请求参数</param>
 6 /// <returns></returns>
 7 public virtual ModelCompareResponse Compare(string accessToken, CompareRequest request)
 8 {
 9     //POST https://api.bimface.com/v2/compare
10     string url = BimfaceConstants.API_HOST + "/v2/compare";
11     string data = request.SerializeToJson();
12 
13     BimFaceHttpHeaders headers = new BimFaceHttpHeaders();
14     headers.AddOAuth2Header(accessToken);
15 
16     try
17     {
18         ModelCompareResponse response;
19 
20         HttpManager httpManager = new HttpManager(headers);
21         HttpResult httpResult = httpManager.Post(url, data);
22         if (httpResult.Status == HttpResult.STATUS_SUCCESS)
23         {
24             response = httpResult.Text.DeserializeJsonToObject<ModelCompareResponse>();
25         }
26         else
27         {
28             response = new ModelCompareResponse
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 类请参考我的博客文章《C# HTTP系列 HttpWebRequest 与 HttpWebResponse》。

CompareRequest 请求类如下:

C#开发BIMFACE系列30 服务端API之模型对比1:发起模型对比
 1 /// <summary>
 2 ///     模型对比请求参数类
 3 /// </summary>
 4 [Serializable]
 5 public class CompareRequest
 6 {
 7     /// <summary>
 8     /// 
 9     /// </summary>
10     /// <param name="followingId">变更后文件ID,如果为删除文件,则为null</param>
11     /// <param name="previousId">变更前文件ID,如果为新增文件,则为null</param>
12     /// <param name="name">自定义对比的名称</param>
13     public CompareRequest(long? followingId, long? previousId, string name = "")
14     {
15         ComparedEntityType = "file"; //要么赋值,必须是正确的值。如果赋值null,则报错
16         Config = null;
17         SourceId = null;
18         Priority = 2;
19         CallBack = "http://www.app.com/receive";
20 
21         FollowingId = followingId;
22         PreviousId = previousId;
23         if (name.IsNullOrWhiteSpace())
24         {
25             Name = DateTime.Now.ToString("yyyyMMddHHmmss") + "对比:" + followingId.ToString2() + "-" + previousId.ToString2();
26         }
27     }
28 
29     /// <summary>
30     ///     对比的模型类型:file
31     /// </summary>
32     [JsonProperty("comparedEntityType", NullValueHandling = NullValueHandling.Ignore)]
33     public string ComparedEntityType { get; set; }
34 
35     [JsonProperty("config", NullValueHandling = NullValueHandling.Ignore)]
36     public object Config { get; set; }
37 
38     /// <summary>
39     ///     变更后文件ID,如果为删除文件,则为null
40     /// </summary>
41     [JsonProperty("followingId")]
42     public long? FollowingId { get; set; }
43 
44     /// <summary>
45     ///     变更前文件ID,如果为新增文件,则为null
46     /// </summary>
47     [JsonProperty("previousId")]
48     public long? PreviousId { get; set; }
49 
50     /// <summary>
51     ///     用户指定对比后的模型的名字
52     /// </summary>
53     [JsonProperty("name")]
54     public string Name { get; set; }
55 
56     /// <summary>
57     ///     第三方应用自己的ID
58     /// </summary>
59     [JsonProperty("sourceId", NullValueHandling = NullValueHandling.Ignore)]
60     public string SourceId { get; set; }
61 
62     /// <summary>
63     ///     对比优先级。取值 1、2、3。数字越大,优先级越低。默认为2
64     /// </summary>
65     [JsonProperty("priority")]
66     public int Priority { get; set; }
67 
68     /// <summary>
69     ///     Callback地址,待转换完毕以后,BIMFace会回调该地址
70     /// </summary>
71     [JsonProperty("callback")]
72     public string CallBack { get; set; }
73 }
View Code

相关文章:

  • 2021-10-09
  • 2021-08-26
  • 2021-07-04
  • 2020-04-23
  • 2021-06-25
  • 2019-09-09
  • 2021-09-29
  • 2019-09-10
猜你喜欢
  • 2021-10-11
  • 2021-11-28
  • 2021-06-25
  • 2021-09-02
  • 2022-02-27
  • 2021-08-12
  • 2021-11-19
相关资源
相似解决方案