| | |
| | | using Autodesk.Revit.Attributes; |
| | | using Autodesk.Revit.UI; |
| | | using HStation.RevitDev.RevitDataExport.Forms; |
| | | using HStation.RevitDev.RevitDataExport.Common; |
| | | using HStation.RevitDev.RevitDataExport.Utility; |
| | | using System; |
| | | using System.IO; |
| | | using System.Reflection; |
| | |
| | | [Transaction(TransactionMode.Manual)] |
| | | public class Application : IExternalApplication |
| | | { |
| | | private readonly string m_familyPanelName = "族列表"; |
| | | UIControlledApplication m_application; |
| | | |
| | | public Result OnShutdown(UIControlledApplication application) |
| | | { |
| | | return Result.Succeeded; |
| | |
| | | |
| | | public Result OnStartup(UIControlledApplication application) |
| | | { |
| | | //创建菜单 管道系统分析 |
| | | CreateRibbon_PipeSystemAnalysis(application); |
| | | m_application = application; |
| | | Ribbon ribbon = new Ribbon(application); |
| | | RibbonPanel ribbonPanel = ribbon.CreateRibbon(); |
| | | ribbonPanel.AddSeparator(); |
| | | GlobalResource.CurrentRevitVersion = application.ControlledApplication.VersionNumber; |
| | | |
| | | //创建菜单 泵系统分析 |
| | | CreateRibbon_PumpSystemAnalysis(application); |
| | | //创建button |
| | | CreateBottons(ribbon, ribbonPanel); |
| | | |
| | | //注册停靠面板 |
| | | RegistDockablePanel(application); |
| | | |
| | | ribbonPanel.AddSeparator(); |
| | | RegistEvent(); |
| | | return Result.Succeeded; |
| | | } |
| | | |
| | | private void CreateRibbon_PumpSystemAnalysis(UIControlledApplication application) |
| | | private static void CreateBottons(Ribbon ribbon, RibbonPanel ribbonPanel) |
| | | { |
| | | application.CreateRibbonTab("泵系统分析"); |
| | | RibbonPanel panel = application.CreateRibbonPanel("泵系统分析", "泵系统分析"); |
| | | string className1 = "HStation.RevitDev.RevitDataExport.PumpSystem"; |
| | | ribbon.CreateButton_SystemAnalysis(ribbonPanel, Enum.YWFamilyType.YWFT_Pump, className1); |
| | | |
| | | string path = Assembly.GetExecutingAssembly().Location; |
| | | string className = "HStation.RevitDev.RevitDataExport.PumpSystemAnalysis"; |
| | | PushButtonData pdata = new PushButtonData("命令按钮", "系统详情", path, className); |
| | | PushButton pBtn = panel.AddItem(pdata) as PushButton; |
| | | string className2 = "HStation.RevitDev.RevitDataExport.ValveSystem"; |
| | | ribbon.CreateButton_SystemAnalysis(ribbonPanel, Enum.YWFamilyType.YWFT_Valve, className2); |
| | | |
| | | string imagePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/Data/Image/analysis.png"; |
| | | pBtn.LargeImage = new BitmapImage(new Uri(imagePath));//32 * 32 |
| | | pBtn.ToolTip = "Revit插件简介"; |
| | | 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 CreateRibbon_PipeSystemAnalysis(UIControlledApplication application) |
| | | private void RegistEvent() |
| | | { |
| | | //1.创建RibbonTab选项卡页 |
| | | application.CreateRibbonTab("义维定制"); |
| | | //2.在RibbonTab选项卡页中创建RibbonPanel面板 |
| | | RibbonPanel panel1 = application.CreateRibbonPanel("义维定制", "管道系统链路检测"); |
| | | |
| | | //3.命令按钮 |
| | | //3.1指定程序集的名称、所使用的类名、程序集路径 |
| | | //程序集路径--最好写成相对位置 |
| | | string Path1 = Assembly.GetExecutingAssembly().Location; |
| | | //程序集的名称、所使用的类名——"主程序集命名空间.主程序类名" |
| | | string Class1 = "RevitDataExport.Export"; |
| | | //3.2定义PushButtonData命令按钮数据资料,绑定程序集 |
| | | PushButtonData pdata = new PushButtonData("命令按钮", "系统详情", Path1, Class1); |
| | | //3.3将PushButton添加到面板中 |
| | | PushButton push = panel1.AddItem(pdata) as PushButton; |
| | | //3.4为PushButton添加图标 |
| | | //可把图片资源加载入项目中,方便把图片的路径写成相对路径,并进行修改属性(图片的生成操作,改位:嵌入的资源) |
| | | Stream imgPath = Assembly.GetExecutingAssembly().GetManifestResourceStream("RevitDataExport.Resources.piping_system_detect2.png"); |
| | | push.LargeImage = BitmapFrame.Create(imgPath); |
| | | //3.5设置命令按钮的默认提示信息 |
| | | push.ToolTip = "Revit插件简介"; |
| | | 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 RegistDockablePanel(UIControlledApplication uiApp) |
| | | private void ControlledApplication_DocumentOpening(object sender, Autodesk.Revit.DB.Events.DocumentOpeningEventArgs e) |
| | | { |
| | | DockablePaneId panelId = new DockablePaneId(new Guid(Common.GlobalResource.Guid_FamilyPanel)); |
| | | Wpf_FamilyPanel panel = new Wpf_FamilyPanel(); |
| | | uiApp.RegisterDockablePane(panelId, m_familyPanelName, panel); |
| | | 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); |
| | | } |
| | | } |
| | | } |