123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
-
- using System;
- using System.IO;
- using System.Linq;
- using Autodesk.Revit.DB;
- using Autodesk.Revit.DB.Mechanical;
- using Newtonsoft.Json.Linq;
- using SAGA.DotNetUtils;
- using SAGA.MBI.Common;
- using SAGA.MBI.DataArrange;
- using SAGA.MBI.Interaction;
- using SAGA.MBI.RequestData;
- using SAGA.MBI.RevitModelHandle;
- using SAGA.Models;
- using SAGA.RevitUtils.Extends;
- using SAGA.RevitUtils.Windows;
- namespace SAGA.MBI
- {
- /// <summary>
- /// revit相关参数哦修改扩展
- /// </summary>
- public static class RevitParameterUpdate
- {
- #region 基础方法
- /// <summary>
- /// 根据bimId获取模型对象
- /// </summary>
- /// <param name="bimId"></param>
- /// <returns></returns>
- public static Element GetElementByBimId(string bimId)
- {
- Element result = null;
- #region 获取revit对象
- if (bimId == null)
- return result;
- var ids = bimId.Split(':');
- if (ids.Count() < 2)
- return result;
- string floorId = ids[0];
- int elementID = ids[1].ToInt();
- var mFloor = DalProjectTree.GetFloorByFloorId(floorId);
- if (mFloor == null)
- {
- return result;
- }
- if (!File.Exists(mFloor.FullPath))
- {
- return result;
- }
- var doc = ExternalDataWrapper.Current.App.OpenDocumentFile(mFloor.FullPath);
- if (doc == null)
- return result;
- result = doc.GetElement(new ElementId(elementID));
- #endregion
- return result;
- }
- #endregion
- #region 同步模型
- #region 触发器控制,方法取消
- ///// <summary>
- ///// 更新模型空间名称
- ///// </summary>
- ///// <param name="element"></param>
- ///// <param name="name"></param>
- ///// <param name="stopLocalTrigger">是否暂停触发器,暂停触发器则不会发送对数据平台的同步</param>
- //public static void UdpateName(this Element element, string name, bool stopLocalTrigger)
- //{
- // if (!stopLocalTrigger)
- // {
- // //UdpateName(element, name);
- // return;
- // }
- // try
- // {
- // MBILocalNameTrigger.Suspend();
- // //UdpateName(element, name);
- // }
- // catch (Exception ex)
- // {
- // }
- // finally
- // {
- // MBILocalNameTrigger.Resume();
- // }
- //}
- #endregion
- public static void UpdateRevitParameter(string bimId, string parameterName,string value)
- {
- if (!ParameterDefinitionFactory.ContainParameter(parameterName))
- return;
- var element = GetElementByBimId(bimId);
- if (element == null)
- return;
-
- ExecuteCmd.ExecuteCommand(() =>
- {
- using (Transaction tran = new Transaction(element.Document, "更改"))
- {
- try
- {
- tran.Start();
- //不检测值是否为null
- UpdateElementByMbi(element, parameterName, value, false);
- tran.Commit();
- }
- catch (Exception e)
- {
- tran.RollBack();
- }
- }
- return Autodesk.Revit.UI.Result.Succeeded;
- });
-
- }
- #endregion
- #region 更新物理世界相关信息
- /// <summary>
- /// 更新空间的名称信息
- /// </summary>
- /// <remarks>触发器使用,现在被砍掉了</remarks>
- /// <param name="element"></param>
- /// <param name="name"></param>
- public static void UpdateMBIName(this Element element, string name)
- {
- //更新物理世界信息点内容
- JArray jArray = CommonTool.GetPropertyJArray(name);
- JObject jObject = new JObject();
- jObject.Add(MBIBuiltInParameter.RoomLocalName, jArray);
- var cloudElement = DalCommon.GetEquipmentQueryId(element);
- if (cloudElement == null || string.IsNullOrWhiteSpace(cloudElement.Id))
- return;
- CommonConvert.UpdateInfosSigle(cloudElement.Id, jObject);
- }
- #endregion
- #region 通过mbi更新,模型信息
- /// <summary>
- /// 更新元素信息值
- /// </summary>
- /// <param name="element"></param>
- /// <param name="mbiParameterName"></param>
- /// <param name="value"></param>
- public static void UpdateElementByMbi(Element element, string mbiParameterName, string value)
- {
- UpdateElementByMbi(element, mbiParameterName, value, true);
- }
- public static void UpdateElementByMbi(Element element, string mbiParameterName, string value, bool checkValueEmpty)
- {
- ////设备信息同步关闭
- //if (element is FamilyInstance)
- // return;
- if (checkValueEmpty && string.IsNullOrWhiteSpace(value))
- return;
- ParameterDefinitionFactory.GetParameterDefinition(mbiParameterName)
- ?.SetParameter(element, value);
- }
- #endregion
- }
- }
|