From 087c55919d833f08d82f4945075dd9cdf567aeff Mon Sep 17 00:00:00 2001 From: qin <a@163.com> Date: 星期四, 24 十月 2024 12:23:03 +0800 Subject: [PATCH] 空压机、帮助、水力计算 --- HStation.RevitDev/RevitDataExport/Plugin/Command.cs | 320 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 295 insertions(+), 25 deletions(-) diff --git a/HStation.RevitDev/RevitDataExport/Plugin/Command.cs b/HStation.RevitDev/RevitDataExport/Plugin/Command.cs index 7874dd7..43a96d3 100644 --- a/HStation.RevitDev/RevitDataExport/Plugin/Command.cs +++ b/HStation.RevitDev/RevitDataExport/Plugin/Command.cs @@ -1,19 +1,25 @@ 锘縰sing Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI; +using DevExpress.Internal.WinApi.Windows.UI.Notifications; +using DevExpress.Utils.Extensions; using DevExpress.XtraPrinting.Native; +using Glodon.Revit.Utility; using HStation.RevitDev.Model.ModelEnum; using HStation.RevitDev.RevitDataExport.Common; using HStation.RevitDev.RevitDataExport.Forms; using HStation.RevitDev.RevitDataExport.Utility; using System; using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; using System.Windows.Forms; namespace HStation.RevitDev.RevitDataExport { /// <summary> - /// 绯荤粺鍒嗙被 + /// 瀵煎叆 /// </summary> [Transaction(TransactionMode.Manual)] public class SystemSelect : IExternalCommand @@ -37,7 +43,7 @@ { var form = new Form_FamilyManager(commandData); var revitHandle = Process.GetCurrentProcess().MainWindowHandle; - form.Show(new WindowHandle(revitHandle)); + form.ShowDialog(new WindowHandle(revitHandle)); return Result.Succeeded; } } @@ -75,6 +81,186 @@ } /// <summary> + /// 姘村姏璁$畻 + /// </summary> + [Transaction(TransactionMode.Manual)] + public class Analy : IExternalCommand + { + UIApplication m_uiapp = null; + ExternalCommandData m_data = null; + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + var uiapp = commandData.Application; + var doc = commandData.Application.ActiveUIDocument.Document; + m_uiapp = uiapp; + m_data = commandData; + + commandData.Application.ActiveUIDocument.Document.UpdataDocumentCache(); + + var results = NetWorkHelper.Check(commandData); + if (results.Any()) + { + SystemCheckUtils.ShowCheckResult(m_uiapp, results); + } + else + { + var ml = NetWorkHelper.GetModelList(commandData); + //var aa = NetWorkHelper.Check(ml, commandData); + var inpPath = GlobalResource.TempInpFilePath; + if (!File.Exists(inpPath)) + File.Create(inpPath).Close(); + + try + { + ml.BuildRelation(); + ml.BuildToInp(inpPath); + var result = NetWorkHelper.Calc(inpPath); + using (var trans = new Transaction(doc, "淇敼灞炴��")) + { + trans.Start(); + //result.ForEach(d => + foreach (var d in result) + { + var ut = ""; + if (!d.Key.Contains("_")) + continue; + try + { + var id = 0; + var pid = d.Key.Split('_')[1]; + if (d.Key.Contains("E__") || d.Key.Contains("S__")) + { + pid = d.Key.Split('_')[3]; + } + id = int.Parse(pid); + var p = d.Key.Split('_')[0]; + var prop = ""; + switch (p) + { + case "Flow": + prop = "娴侀噺"; + ut = " (m鲁/h)"; + break; + case "Velocity": + prop = "娴侀��"; + ut = " (m/s)"; + break; + case "Headloss": + prop = "姘存崯"; + ut = " (m)"; + break; + case "Press": + prop = "鍘嬪姏"; + ut = " (m)"; + break; + //case "Head": + // prop = "鍘嬪姏"; + // break; + case "Demand": + prop = "娴侀噺"; + ut = " (m鲁/h)"; + if (d.Key.Contains("S__")) + { + prop = "杩涘彛鍘嬪姏"; + ut = " (m)"; + } + else if (d.Key.Contains("E__")) + { + prop = "鍑哄彛鍘嬪姏"; + ut = " (m)"; + } + + break; + } + var vu = d.Value.ToString("0.000"); + + var eid = new ElementId(id); + var ele = doc.GetElement(eid); + if (ele != null) + { + var pro = ele.GetParameterByProName(prop); + if (pro != null) + { + + if (prop.Equals("娴侀噺") && !vu.Contains("E")) + vu = Math.Abs(decimal.Parse(vu)).ToString("0.000"); + if (pro != null && !pro.IsReadOnly && pro.StorageType == StorageType.String) + { + pro.Set(vu + ut); + } + + var ps = ele.GetParameters(prop); + if (ps != null) + { + var sp = ps.FirstOrDefault(c => !c.IsReadOnly && c.StorageType == StorageType.String); + if (sp != null) + sp.Set(vu + ut); + } + + + } + } + } + catch (Exception ex) + { + var err = ex.Message; + } + }; + + ml.pumps.ForEach(p => + { + if (result.Any()) + { + var p1 = result.FirstOrDefault(c => c.Key == "Press_" + p.Node1).Value; + var p2 = result.FirstOrDefault(c => c.Key == "Press_" + p.Node2).Value; + + var eid = new ElementId(int.Parse(p.ID)); + var ele = doc.GetElement(eid); + if (ele != null) + { + var pro1 = ele.GetParameterByProName("杩涘彛鍘嬪姏"); + var pro2 = ele.GetParameterByProName("鍑哄彛鍘嬪姏"); + if (pro1 != null) + pro1.Set(Math.Abs(p1) > Math.Abs(p2) ? Math.Abs(p2).ToString("0.000") + " (m)" : Math.Abs(p1).ToString("0.000") + " (m)"); + if (pro2 != null) + pro2.Set(Math.Abs(p1) > Math.Abs(p2) ? Math.Abs(p1).ToString("0.000") + " (m)" : Math.Abs(p2).ToString("0.000") + " (m)"); + + } + } + }); + + trans.Commit(); + } + + TaskDialog.Show("鎻愮ず", "璁$畻鎴愬姛!"); + } + catch (Exception ex) + { + TaskDialog.Show("閿欒", "璁$畻閿欒锛�" + ex.Message); + } + } + return Result.Succeeded; + } + + + } + + /// <summary> + /// 鍏跺畠涓�閿樉闅� + /// </summary> + [Transaction(TransactionMode.Manual)] + public class HideOtherModels : IExternalCommand + { + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + var doc = commandData.Application.ActiveUIDocument.Document; + commandData.Application.ActiveUIDocument.Document.UpdataDocumentCache(); + CacheUtil.HideOrShowOtherModels(commandData.Application.ActiveUIDocument.Document); + return Result.Succeeded; + } + } + + /// <summary> /// 绯荤粺妫�鏌� /// </summary> [Transaction(TransactionMode.Manual)] @@ -91,32 +277,36 @@ m_data = commandData; doc.UpdataDocumentCache(); - m_uiapp.Idling += App_Idling; - RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.CheckPipeSystems); - if (uiapp.CanPostCommand(id)) - { - uiapp.PostCommand(id); - } + var results = NetWorkHelper.Check(commandData);// SystemCheckUtils.SystemCheck(m_data); + if (results != null && results.Any()) + SystemCheckUtils.ShowCheckResult(m_uiapp, results); + else + TaskDialog.Show("绯荤粺妫�鏌�", "绯荤粺妫�鏌ラ�氳繃 !"); + //m_uiapp.Idling += App_Idling; + //RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.ShowDisconnects); + //if (uiapp.CanPostCommand(id)) + //{ + // uiapp.PostCommand(id); + //} return Result.Succeeded; } - private void App_Idling(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs e) - { - if (m_isFirstTrigger) - { - m_isFirstTrigger = false; - } - else - { - SystemCheckUtils.SystemCheck(m_data); - m_uiapp.Idling -= App_Idling; - m_isFirstTrigger = true; - } - } + //private void App_Idling(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs e) + //{ + // if (m_isFirstTrigger) + // { + // m_isFirstTrigger = false; + // } + // else + // { + // var results = SystemCheckUtils.SystemCheck(m_data); + // SystemCheckUtils.ShowCheckResult(m_uiapp, results); + // m_uiapp.Idling -= App_Idling; + // m_isFirstTrigger = true; + // } + //} } - - /// <summary> /// 瀵煎嚭妯″瀷 @@ -127,9 +317,56 @@ public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var doc = commandData.Application.ActiveUIDocument.Document; + if (string.IsNullOrEmpty(doc.PathName)) + { + TaskDialog.Show("鎻愮ず", "璇峰厛淇濆瓨妯″瀷鍚庡啀杩涜瀵煎嚭鎿嶄綔!"); + return Result.Failed; + } doc.UpdataDocumentCache(); + CacheUtil.SaveCache(commandData.Application.ActiveUIDocument.Document); - TaskDialog.Show("鎻愮ず", "瀵煎嚭瀹屾垚锛�"); + var result = CacheUtil.ExportZipFile(doc, out string err); + if (result) + TaskDialog.Show("鎻愮ず", "鏂囦欢瀵煎嚭瀹屾垚锛�"); + else TaskDialog.Show("鎻愮ず", "瀵煎嚭澶辫触锛�" + err); + return Result.Succeeded; + } + } + + /// <summary> + /// 涓婁紶妯″瀷 + /// </summary> + [Transaction(TransactionMode.Manual)] + public class UploadModels : IExternalCommand + { + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + var doc = commandData.Application.ActiveUIDocument.Document; + if (string.IsNullOrEmpty(doc.PathName)) + { + TaskDialog.Show("鎻愮ず", "璇峰厛淇濆瓨妯″瀷鍚庡啀杩涜瀵煎嚭鎿嶄綔!"); + return Result.Failed; + } + doc.UpdataDocumentCache(); + + CacheUtil.SaveCache(commandData.Application.ActiveUIDocument.Document); + var result = CacheUtil.UploadFile(doc, out string err); + if (result) + TaskDialog.Show("鎻愮ず", "鏂囦欢涓婁紶瀹屾垚锛�"); + else TaskDialog.Show("鎻愮ず", "涓婁紶澶辫触锛�" + err); + return Result.Succeeded; + } + } + + /// <summary> + /// 甯姪 + /// </summary> + [Transaction(TransactionMode.Manual)] + public class Help : IExternalCommand + { + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + Process.Start(new ProcessStartInfo("https://www.yuque.com/yiweikeji-stofk/lu5dm6?#") { UseShellExecute = true }); return Result.Succeeded; } } @@ -165,6 +402,8 @@ } } + + /// <summary> /// 闃�闂� /// </summary> @@ -181,12 +420,27 @@ } /// <summary> - /// 鎹㈢儹姘� + /// 鎹㈢儹鍣� /// </summary> [Transaction(TransactionMode.Manual)] public class HeatExchangerSystem : IExternalCommand { RevitType m_type = RevitType.RFT_HeatExchanger; + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + DocumentUtil.RegistDocumentEvent(commandData); + DockablePaneUtils.ShowDockablePanel(commandData, m_type); + return Result.Succeeded; + } + } + + /// <summary> + /// 绌哄帇鏈� + /// </summary> + [Transaction(TransactionMode.Manual)] + public class WindTurbineSystem : IExternalCommand + { + RevitType m_type = RevitType.RFT_WindTurbine; public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { DocumentUtil.RegistDocumentEvent(commandData); @@ -345,6 +599,22 @@ } } + /// <summary> + /// 鑷畾涔� + /// </summary> + [Transaction(TransactionMode.Manual)] + public class CustomizeSystem : IExternalCommand + { + RevitType m_type = RevitType.RFT_Customize; + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + GlobalResource.CurrentAddinId = commandData.Application.ActiveAddInId; + DocumentUtil.RegistDocumentEvent(commandData); + DockablePaneUtils.ShowDockablePanel(commandData, m_type); + return Result.Succeeded; + } + } + public class WindowHandle : IWin32Window { private IntPtr _handle; -- Gitblit v1.9.3