| | |
| | | using Autodesk.Revit.Attributes; |
| | | using Autodesk.Revit.DB; |
| | | using Autodesk.Revit.UI; |
| | | using HStation.RevitDev.RevitDataExport.Common; |
| | | using HStation.RevitDev.RevitDataExport.Utility; |
| | | using System; |
| | | using System.IO; |
| | | 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; |
| | | Ribbon ribbon = new Ribbon(application); |
| | | RibbonPanel ribbonPanel = ribbon.CreateRibbon(); |
| | | ribbonPanel.AddSeparator(); |
| | | GlobalResource.CurrentRevitVersion = application.ControlledApplication.VersionNumber; |
| | | |
| | | CreateBottons(ribbon, ribbonPanel); |
| | | |
| | | ribbonPanel.AddSeparator(); |
| | | RegistEvent(); |
| | | return Result.Succeeded; |
| | | } |
| | | |
| | | private static void CreateBottons(Ribbon ribbon, RibbonPanel ribbonPanel) |
| | | { |
| | | string className1 = "HStation.RevitDev.RevitDataExport.PumpSystem"; |
| | | ribbon.CreateButton_SystemAnalysis(ribbonPanel, Enum.YWFamilyType.YWFT_Pump, className1); |
| | | |
| | | string className2 = "HStation.RevitDev.RevitDataExport.ValveSystem"; |
| | | ribbon.CreateButton_SystemAnalysis(ribbonPanel, Enum.YWFamilyType.YWFT_Valve, className2); |
| | | |
| | | string className3 = "HStation.RevitDev.RevitDataExport.PipeSystem"; |
| | | ribbon.CreateButton_PipeSystem(ribbonPanel, Enum.YWFamilyType.YWFT_Pipe, className3); |
| | | |
| | | string className4 = "HStation.RevitDev.RevitDataExport.HeatExchangerSystem"; |
| | | ribbon.CreateButton_SystemAnalysis(ribbonPanel, Enum.YWFamilyType.YWFT_Heat_Exchanger, className4); |
| | | |
| | | string className5 = "HStation.RevitDev.RevitDataExport.BlockerSystem"; |
| | | ribbon.CreateButton_SystemAnalysis(ribbonPanel, Enum.YWFamilyType.YWFT_Blocker, className5); |
| | | |
| | | string className6 = "HStation.RevitDev.RevitDataExport.ShowerSystem"; |
| | | ribbon.CreateButton_SystemAnalysis(ribbonPanel, Enum.YWFamilyType.YWFT_Shower, className6); |
| | | |
| | | string className7 = "HStation.RevitDev.RevitDataExport.ThreeJointSystem"; |
| | | ribbon.CreateButton_SystemAnalysis(ribbonPanel, Enum.YWFamilyType.YWFT_Three_Joint, className7); |
| | | |
| | | string className8 = "HStation.RevitDev.RevitDataExport.FourJointSystem"; |
| | | ribbon.CreateButton_SystemAnalysis(ribbonPanel, Enum.YWFamilyType.YWFT_Four_Joint, className8); |
| | | |
| | | string className9 = "HStation.RevitDev.RevitDataExport.WaterMeterSystem"; |
| | | ribbon.CreateButton_SystemAnalysis(ribbonPanel, Enum.YWFamilyType.YWFT_Water_Meter, className9); |
| | | |
| | | string className10 = "HStation.RevitDev.RevitDataExport.WaterPoolSystem"; |
| | | ribbon.CreateButton_SystemAnalysis(ribbonPanel, Enum.YWFamilyType.YWFT_Water_Pool, className10); |
| | | |
| | | string className11 = "HStation.RevitDev.RevitDataExport.WaterBoxSystem"; |
| | | ribbon.CreateButton_SystemAnalysis(ribbonPanel, Enum.YWFamilyType.YWFT_Water_Box, className11); |
| | | |
| | | string className12 = "HStation.RevitDev.RevitDataExport.ElbowSystem"; |
| | | ribbon.CreateButton_SystemAnalysis(ribbonPanel, Enum.YWFamilyType.YWFT_Elbow, className12); |
| | | |
| | | string className13 = "HStation.RevitDev.RevitDataExport.FireHydrantSystem"; |
| | | ribbon.CreateButton_SystemAnalysis(ribbonPanel, Enum.YWFamilyType.YWFT_Fire_Hydrant, className13); |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | | 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) |
| | | { |
| | | DockPaneUtil.HideAllDockablePane(m_application); |
| | | } |
| | | |
| | | private void ControlledApplication_DocumentOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e) |
| | | { |
| | | DockPaneUtil.HideAllDockablePane(m_application); |
| | | } |
| | | |
| | | private void ControlledApplication_DocumentCreating(object sender, Autodesk.Revit.DB.Events.DocumentCreatingEventArgs e) |
| | | { |
| | | DockPaneUtil.HideAllDockablePane(m_application); |
| | | } |
| | | } |
| | | } |
| | | 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);
|
| | | CreateVisibleOtherBotton(ribbon, panel3);
|
| | |
|
| | | //拓扑检查
|
| | | RibbonPanel panel4 = ribbon.CreatePanel("拓扑检查");
|
| | | CreateCheckBotton(ribbon, panel4);
|
| | | DockPaneUtil.RegistInstanceDockablePanel(application);
|
| | |
|
| | | //计算分析
|
| | | RibbonPanel panel5 = ribbon.CreatePanel("计算分析");
|
| | | CreateAnalyBotton(ribbon, panel5);
|
| | |
|
| | | //系统管理
|
| | | RibbonPanel panel6 = ribbon.CreatePanel("系统管理");
|
| | | CreateAutoClassifiedBotton(ribbon, panel6);
|
| | | CreateFamilyManagerBotton(ribbon, panel6);
|
| | |
|
| | | 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 CreateAnalyBotton(Ribbon ribbon, RibbonPanel ribbonPanel)
|
| | | {
|
| | | //Check Links
|
| | | string className = "HStation.RevitDev.RevitDataExport.Analy";
|
| | | 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 CreateVisibleOtherBotton(Ribbon ribbon, RibbonPanel ribbonPanel)
|
| | | {
|
| | | //Hide Or Display Models
|
| | | string className = "HStation.RevitDev.RevitDataExport.HideOtherModels";
|
| | | string path = Assembly.GetExecutingAssembly().Location;
|
| | |
|
| | | PushButtonData pdata = new PushButtonData("HideOther", "其它显隐", 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);
|
| | |
|
| | | //换热器
|
| | | if (GlobalResource.ConfigSettingModel.SystemType == ConfigHelper.SystemType.All || GlobalResource.ConfigSettingModel.SystemType == ConfigHelper.SystemType.CirculatingWater)
|
| | | {
|
| | | 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);
|
| | |
|
| | | //喷淋头
|
| | | if (GlobalResource.ConfigSettingModel.SystemType == ConfigHelper.SystemType.All || GlobalResource.ConfigSettingModel.SystemType == ConfigHelper.SystemType.Spray)
|
| | | {
|
| | | 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);
|
| | |
|
| | | //消火栓
|
| | | if (GlobalResource.ConfigSettingModel.SystemType == ConfigHelper.SystemType.All || GlobalResource.ConfigSettingModel.SystemType == ConfigHelper.SystemType.Fire)
|
| | | {
|
| | | 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<string, Dictionary<RevitType, List<string>>>(doc.Title, new Dictionary<RevitType, List<string>>()));
|
| | | }
|
| | | }
|
| | |
|
| | | 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);
|
| | | }
|
| | | }
|
| | | }
|