C#开发BIMFACE系列34 服务端API之模型对比5:获取模型构件对比差异

BIMFACE平台提供了服务端“获取修改构件属性差异”API,其返回的结果也是一个列表,仅针对修改的构件(不包含新增、删除的构件),是指对于一个修改过的构件ID,其修改前后分别新增、删除了哪些属性,或是属性值发生了变化。
请求地址:GET https://api.bimface.com/data/v2/comparisons/{comparisonId}/elementChange
参数:
请求 path(示例):https://api.bimface.com/data/v2/comparisons/1136906400211168/elementChange?followingElementId=296524&followingFileId=1136893002033344&previousElementId=296524&previousFileId=1136239003943104
请求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"
HTTP响应示例(200):
1 { 2 "code" : "success", 3 "data" : { 4 "_A" : "string", 5 "_B" : "string", 6 "changeAttributes" : [ { 7 "_A" : { 8 "key" : "key", 9 "unit" : "unit", 10 "value" : "value" 11 }, 12 "_B" : { 13 "key" : "key", 14 "unit" : "unit", 15 "value" : "value" 16 } 17 } ], 18 "changeQuantities" : [ { 19 "_A" : { 20 "code" : "code", 21 "desc" : "desc", 22 "name" : "name", 23 "qty" : 0, 24 "unit" : "unit" 25 }, 26 "_B" : { 27 "code" : "code", 28 "desc" : "desc", 29 "name" : "name", 30 "qty" : 0, 31 "unit" : "unit" 32 } 33 } ], 34 "deleteAttributes" : [ { 35 "key" : "key", 36 "unit" : "unit", 37 "value" : "value" 38 } ], 39 "deleteQuantities" : [ { 40 "code" : "code", 41 "desc" : "desc", 42 "name" : "name", 43 "qty" : 0, 44 "unit" : "unit" 45 } ], 46 "newAttributes" : [ { 47 "key" : "key", 48 "unit" : "unit", 49 "value" : "value" 50 } ], 51 "newQuantities" : [ { 52 "code" : "code", 53 "desc" : "desc", 54 "name" : "name", 55 "qty" : 0, 56 "unit" : "unit" 57 } ] 58 }, 59 "message" : "" 60 }
C#实现方法:
1 /// <summary> 2 /// 获取模型构件对比差异 3 /// </summary> 4 /// <param name="accessToken">【必填】令牌</param> 5 /// <param name="compareId">【必填】对比ID</param> 6 /// <param name="followingFileId">【必填】变更后的文件ID</param> 7 /// <param name="followingElementId">【必填】变更后的文件的构件ID</param> 8 /// <param name="previousFileId">【必填】变更前的文件ID</param> 9 /// <param name="previousElementId">【必填】变更前的文件的构件ID</param> 10 /// <returns></returns> 11 public virtual ModelCompareChangeResponse GetModelCompareChange(string accessToken, long compareId, 12 long followingFileId, string followingElementId, long previousFileId, string previousElementId) 13 { 14 // GET https: //api.bimface.com/data/v2/comparisons/{comparisonId}/elementChange 15 string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/comparisons/{0}/elementChange", compareId); 16 url += "?followingFileId=" + followingFileId; 17 url += "&followingElementId=" + followingElementId; 18 url += "&previousFileId=" + previousFileId; 19 url += "&previousElementId=" + previousElementId; 20 21 BimFaceHttpHeaders headers = new BimFaceHttpHeaders(); 22 headers.AddOAuth2Header(accessToken); 23 24 try 25 { 26 ModelCompareChangeResponse response; 27 28 HttpManager httpManager = new HttpManager(headers); 29 HttpResult httpResult = httpManager.Get(url); 30 if (httpResult.Status == HttpResult.STATUS_SUCCESS) 31 { 32 response = httpResult.Text.DeserializeJsonToObject<ModelCompareChangeResponse>(); 33 } 34 else 35 { 36 response = new ModelCompareChangeResponse 37 { 38 Message = httpResult.RefText 39 }; 40 } 41 42 return response; 43 } 44 catch (Exception ex) 45 { 46 throw new Exception("[获取模型构件对比差异]发生异常!", ex); 47 } 48 }
代码中使用的 HttpManager 类请参考我的博客文章《C# HTTP系列 HttpWebRequest 与 HttpWebResponse》。
返回类型 ModelCompareChangeResponse 类如下:
1 /// <summary> 2 /// 获取模型构件对比差异的响应类 3 /// </summary> 4 public class ModelCompareChangeResponse : GeneralResponse<ModelCompareChange> 5 { 6 7 } 8 9 /// <summary> 10 /// 模型构件对比差异类 11 /// </summary> 12 public class ModelCompareChange 13 { 14 /// <summary> 15 /// 变化图元前一个版本的ID 16 /// </summary> 17 [JsonProperty("_A", NullValueHandling = NullValueHandling.Ignore)] 18 public string A { get; set; } 19 20 /// <summary> 21 /// 变化图元后一个版本的ID 22 /// </summary> 23 [JsonProperty("_B", NullValueHandling = NullValueHandling.Ignore)] 24 public string B { get; set; } 25 26 /// <summary> 27 /// 变更的构建属性集合 28 /// </summary> 29 30 [JsonProperty("changeAttributes", NullValueHandling = NullValueHandling.Ignore)] 31 public ChangeAttributes[] ChangeAttributes { get; set; } 32 33 /// <summary> 34 /// 变更的工程量集合 35 /// </summary> 36 37 [JsonProperty("changeQuantities", NullValueHandling = NullValueHandling.Ignore)] 38 public ChangeQuantities[] ChangeQuantities { get; set; } 39 40 /// <summary> 41 /// 删除的构建属性集合 42 /// </summary> 43 44 [JsonProperty("deleteAttributes", NullValueHandling = NullValueHandling.Ignore)] 45 public Attribute[] DeleteAttributes { get; set; } 46 47 /// <summary> 48 /// 删除的工程量集合 49 /// </summary> 50 51 [JsonProperty("deleteQuantities", NullValueHandling = NullValueHandling.Ignore)] 52 public Quantity[] DeleteQuantities { get; set; } 53 54 /// <summary> 55 /// 新增的构建属性集合 56 /// </summary> 57 58 [JsonProperty("newAttributes", NullValueHandling = NullValueHandling.Ignore)] 59 public Attribute[] NewAttributes { get; set; } 60 61 /// <summary> 62 /// 新增的工程量集合 63 /// </summary> 64 65 [JsonProperty("newQuantities", NullValueHandling = NullValueHandling.Ignore)] 66 public Quantity[] NewQuantities { get; set; } 67 } 68 69 /// <summary> 70 /// 变更的构建属性 71 /// </summary> 72 public class ChangeAttributes 73 { 74 /// <summary> 75 /// 前一个版本 76 /// </summary> 77 [JsonProperty("_A", NullValueHandling = NullValueHandling.Ignore)] 78 public Attribute A { get; set; } 79 80 /// <summary> 81 /// 后一个版本 82 /// </summary> 83 [JsonProperty("_B", NullValueHandling = NullValueHandling.Ignore)] 84 public Attribute B { get; set; } 85 } 86 87 /// <summary> 88 /// 变更的工程量 89 /// </summary> 90 public class ChangeQuantities 91 { 92 /// <summary> 93 /// 前一个版本 94 /// </summary> 95 [JsonProperty("_A", NullValueHandling = NullValueHandling.Ignore)] 96 public Quantity A { get; set; } 97 98 /// <summary> 99 /// 后一个版本 100 /// </summary> 101 [JsonProperty("_B", NullValueHandling = NullValueHandling.Ignore)] 102 public Quantity B { get; set; } 103 } 104 105 /// <summary> 106 /// 构建属性 107 /// </summary> 108 public class Attribute 109 { 110 [JsonProperty("key", NullValueHandling = NullValueHandling.Ignore)] 111 public string Key { get; set; } 112 113 [JsonProperty("value", NullValueHandling = NullValueHandling.Ignore)] 114 public string Value { get; set; } 115 116 [JsonProperty("unit", NullValueHandling = NullValueHandling.Ignore)] 117 public string Unit { get; set; } 118 } 119 120 /// <summary> 121 /// 工程量 122 /// </summary> 123 public class Quantity 124 { 125 [JsonProperty("code", NullValueHandling = NullValueHandling.Ignore)] 126 public string Code { get; set; } 127 128 [JsonProperty("desc", NullValueHandling = NullValueHandling.Ignore)] 129 public string Desc { get; set; } 130 131 [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] 132 public string Name { get; set; } 133 134 [JsonProperty("qty", NullValueHandling = NullValueHandling.Ignore)] 135 public string Qty { get; set; } 136 137 [JsonProperty("unit", NullValueHandling = NullValueHandling.Ignore)] 138 public string Unit { get; set; } 139 }

成在管理,败在经验;嬴在选择,输在不学! 贵在坚持!
个人作品
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、AI、DeepSeek、MiniMax、通义千问
2、Visual Studio、.NET Core/.NET、MVC、Web API、RESTful API、gRPC、SignalR、Java、Python
3、jQuery、Vue.js、Bootstrap、ElementUI
4、数据库:分库分表、读写分离、SQLServer、MySQL、PostgreSQL、Redis、MongoDB、ElasticSearch、达梦DM、GaussDB、OpenGauss
5、架构:DDD、ABP、SpringBoot、jFinal
6、环境:跨平台、Windows、Linux
7、移动App:Android、IOS、HarmonyOS、微信小程序、钉钉、uni-app、MAUI
8、分布式、高并发、云原生、微服务、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联系。共同交流、互相学习。
如果您觉得文章对您有帮助,请点击文章右下角【推荐】。您的鼓励是作者持续创作的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?