using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using HStation.RevitDev.Model.ModelEnum; using HStation.RevitDev.RevitDataExport.Common; using HStation.RevitDev.RevitDataExport.Entity; using HStation.RevitDev.RevitDataExport.Utility; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Reflection; using System.Windows.Media.Imaging; namespace HStation.RevitDev.RevitDataExport.Plugin { [Transaction(TransactionMode.Manual)] public class Application : IExternalApplication { UIControlledApplication m_application; public Result OnShutdown(UIControlledApplication application) { return Result.Succeeded; } public Result OnStartup(UIControlledApplication application) { m_application = application; GlobalResource.CurrentRevitVersion = application.ControlledApplication.VersionNumber; Ribbon ribbon = new Ribbon(application); //水力组件 RibbonPanel panel1 = ribbon.CreatePanel("水力组件"); CreateFamilyBottons(ribbon, panel1); //导入导出 RibbonPanel panel2 = ribbon.CreatePanel("导入导出"); CreateExportBottons(ribbon, panel2); CreateSystemSelectBotton(ribbon, panel2); //显示控制 RibbonPanel panel3 = ribbon.CreatePanel("显示控制"); CreateVisibleBotton(ribbon, panel3); //拓扑检查 RibbonPanel panel4 = ribbon.CreatePanel("拓扑检查"); CreateCheckBotton(ribbon, panel4); DockPaneUtil.RegistInstanceDockablePanel(application); //系统管理 RibbonPanel panel5 = ribbon.CreatePanel("系统管理"); CreateAutoClassifiedBotton(ribbon, panel4); CreateFamilyManagerBotton(ribbon, panel5); RegistEvent(); return Result.Succeeded; } private void CreateFamilyManagerBotton(Ribbon ribbon, RibbonPanel ribbonPanel) { //SystemSelect string className = "HStation.RevitDev.RevitDataExport.FamilyManager"; string path = Assembly.GetExecutingAssembly().Location; PushButtonData pdata = new PushButtonData("FamilyManager", "族库管理", path, className); PushButton pBtn = ribbonPanel.AddItem(pdata) as PushButton; string imagePath = Path.Combine(GlobalResource.ImageDirectory, $"族库管理.png"); pBtn.LargeImage = new BitmapImage(new Uri(imagePath));//32 * 32 pBtn.ToolTip = "族库管理"; } private void CreateSystemSelectBotton(Ribbon ribbon, RibbonPanel ribbonPanel) { //SystemSelect string className = "HStation.RevitDev.RevitDataExport.SystemSelect"; string path = Assembly.GetExecutingAssembly().Location; PushButtonData pdata = new PushButtonData("SystemSelect", "导入", path, className); PushButton pBtn = ribbonPanel.AddItem(pdata) as PushButton; string imagePath = Path.Combine(GlobalResource.ImageDirectory, $"系统分类.png"); pBtn.LargeImage = new BitmapImage(new Uri(imagePath));//32 * 32 pBtn.ToolTip = "导入"; } private void CreateAutoClassifiedBotton(Ribbon ribbon, RibbonPanel ribbonPanel) { //Classified Elements string className = "HStation.RevitDev.RevitDataExport.AutoClassified"; string path = Assembly.GetExecutingAssembly().Location; PushButtonData pdata = new PushButtonData("AutoClassified", "构件分类", path, className); PushButton pBtn = ribbonPanel.AddItem(pdata) as PushButton; string imagePath = Path.Combine(GlobalResource.ImageDirectory, $"构件分类.png"); pBtn.LargeImage = new BitmapImage(new Uri(imagePath));//32 * 32 pBtn.ToolTip = "构件分类"; } private void CreateCheckBotton(Ribbon ribbon, RibbonPanel ribbonPanel) { //Check Links string className = "HStation.RevitDev.RevitDataExport.SystemCheck"; string path = Assembly.GetExecutingAssembly().Location; PushButtonData pdata = new PushButtonData("Check", "系统检查", path, className); PushButton pBtn = ribbonPanel.AddItem(pdata) as PushButton; string imagePath = Path.Combine(GlobalResource.ImageDirectory, $"系统检查.png"); pBtn.LargeImage = new BitmapImage(new Uri(imagePath));//32 * 32 pBtn.ToolTip = "系统检查 "; } private void CreateVisibleBotton(Ribbon ribbon, RibbonPanel ribbonPanel) { //Hide Or Display Models string className = "HStation.RevitDev.RevitDataExport.HideModels"; string path = Assembly.GetExecutingAssembly().Location; PushButtonData pdata = new PushButtonData("Hide", "一键显隐", path, className); PushButton pBtn = ribbonPanel.AddItem(pdata) as PushButton; string imagePath = Path.Combine(GlobalResource.ImageDirectory, $"一键显隐.png"); pBtn.LargeImage = new BitmapImage(new Uri(imagePath));//32 * 32 pBtn.ToolTip = "一键显隐"; } private void CreateExportBottons(Ribbon ribbon, RibbonPanel ribbonPanel) { string className = "HStation.RevitDev.RevitDataExport.ExportModels"; string path = Assembly.GetExecutingAssembly().Location; PushButtonData pdata = new PushButtonData("Export", "导出", path, className); PushButton pBtn = ribbonPanel.AddItem(pdata) as PushButton; string imagePath = Path.Combine(GlobalResource.ImageDirectory, $"导出.png"); pBtn.LargeImage = new BitmapImage(new Uri(imagePath));//32 * 32 pBtn.ToolTip = "导出模型数据"; } private static void CreateFamilyBottons(Ribbon ribbon, RibbonPanel ribbonPanel) { string className1 = "HStation.RevitDev.RevitDataExport.PumpSystem"; ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_Pump, className1); string className2 = "HStation.RevitDev.RevitDataExport.ValveSystem"; ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_Valve, className2); string className3 = "HStation.RevitDev.RevitDataExport.PipeSystem"; ribbon.CreateButton_PipeSystem(ribbonPanel, RevitType.RFT_Pipe, className3); string className4 = "HStation.RevitDev.RevitDataExport.HeatExchangerSystem"; ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_HeatExchanger, className4); string className5 = "HStation.RevitDev.RevitDataExport.BlockerSystem"; ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_Blocker, className5); string className6 = "HStation.RevitDev.RevitDataExport.ShowerSystem"; ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_Shower, className6); string className7 = "HStation.RevitDev.RevitDataExport.ThreeJointSystem"; ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_ThreeJoint, className7); string className8 = "HStation.RevitDev.RevitDataExport.FourJointSystem"; ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_FourJoint, className8); string className9 = "HStation.RevitDev.RevitDataExport.WaterMeterSystem"; ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_WaterMeter, className9); string className10 = "HStation.RevitDev.RevitDataExport.WaterPoolSystem"; ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_WaterPool, className10); string className11 = "HStation.RevitDev.RevitDataExport.WaterBoxSystem"; ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_WaterBox, className11); string className12 = "HStation.RevitDev.RevitDataExport.ElbowSystem"; ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_Elbow, className12); string className13 = "HStation.RevitDev.RevitDataExport.FireHydrantSystem"; ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_FireHydrant, className13); string className14 = "HStation.RevitDev.RevitDataExport.ReducingSystem"; ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_Converter, className14); } private void RegistEvent() { m_application.ControlledApplication.DocumentOpened += ControlledApplication_DocumentOpened; m_application.ControlledApplication.DocumentOpening += ControlledApplication_DocumentOpening; m_application.ControlledApplication.DocumentCreated += ControlledApplication_DocumentCreated; m_application.ControlledApplication.DocumentCreating += ControlledApplication_DocumentCreating; m_application.ControlledApplication.DocumentSaved += ControlledApplication_DocumentSaved; m_application.ControlledApplication.DocumentSavedAs += ControlledApplication_DocumentSavedAs; } private void ControlledApplication_DocumentSavedAs(object sender, Autodesk.Revit.DB.Events.DocumentSavedAsEventArgs e) { CacheUtil.SaveCache(e.Document); } private void ControlledApplication_DocumentSaved(object sender, Autodesk.Revit.DB.Events.DocumentSavedEventArgs e) { CacheUtil.SaveCache(e.Document); } private void ControlledApplication_DocumentOpening(object sender, Autodesk.Revit.DB.Events.DocumentOpeningEventArgs e) { DockPaneUtil.HideAllDockablePane(m_application); } private void ControlledApplication_DocumentCreated(object sender, Autodesk.Revit.DB.Events.DocumentCreatedEventArgs e) { var doc = e.Document; GlobalResource.CurrentDocument = e.Document; DockPaneUtil.HideAllDockablePane(m_application); var cache = GlobalResource.RevitModels.Find(x => x.Item1 == doc.Title); if (cache == null) { GlobalResource.RevitModels.Add(new Tuple>>(doc.Title, new Dictionary>())); } } private void ControlledApplication_DocumentOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e) { DockPaneUtil.HideAllDockablePane(m_application); GlobalResource.CurrentDocument = e.Document; CacheUtil.InitCache(e.Document); DocumentUtil.UpdataDocumentCache(e.Document); } private void ControlledApplication_DocumentCreating(object sender, Autodesk.Revit.DB.Events.DocumentCreatingEventArgs e) { DockPaneUtil.HideAllDockablePane(m_application); } } }