zhangyk-c
2024-07-11 9ca59ac2d37530208538a05a704b5ea712cab7db
HStation.RevitDev/RevitDataExport/Plugin/Application.cs
@@ -1,5 +1,8 @@
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI;
using HStation.RevitDev.RevitDataExport.Forms;
using Spire.AI.Api;
using System;
using System.IO;
using System.Reflection;
using System.Windows.Media.Imaging;
@@ -9,6 +12,8 @@
    [Transaction(TransactionMode.Manual)]
    public class Application : IExternalApplication
    {
        UIControlledApplication m_uiControlledApp;
        private readonly string m_familyPanelName = "族列表";
        public Result OnShutdown(UIControlledApplication application)
        {
            return Result.Succeeded;
@@ -16,7 +21,66 @@
        public Result OnStartup(UIControlledApplication application)
        {
            //创建自定义Ribbon菜单
            m_uiControlledApp = application;
            //创建菜单 管道系统分析
            CreateRibbon_PipeSystemAnalysis(application);
            //创建菜单 泵系统分析
            CreateRibbon_PumpSystemAnalysis(application);
            return Result.Succeeded;
        }
        private void CreateRibbon_PumpSystemAnalysis(UIControlledApplication application)
        {
            application.CreateRibbonTab("泵系统分析");
            RibbonPanel panel = application.CreateRibbonPanel("泵系统分析", "泵系统分析");
            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 imagePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "../../../../Data/Image/analysis.png";
            pBtn.LargeImage = new BitmapImage(new Uri(imagePath));//32 * 32
            pBtn.ToolTip = "Revit插件简介";
            //注册停靠面板
            RegistDockablePanel(application);
            application.ControlledApplication.DocumentOpened += ControlledApplication_DocumentOpened;
            application.ControlledApplication.DocumentCreated += ControlledApplication_DocumentCreated;
        }
        private void ControlledApplication_DocumentCreated(object sender, Autodesk.Revit.DB.Events.DocumentCreatedEventArgs e)
        {
            HideDockablePane();
        }
        private void ControlledApplication_DocumentOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e)
        {
            HideDockablePane();
        }
        private void HideDockablePane()
        {
            Guid guid = new Guid(Common.GlobalResource.Guid_FamilyPanel);
            DockablePaneId id = new DockablePaneId(guid);
            DockablePane pane = null;
            try
            {
                pane = m_uiControlledApp.GetDockablePane(id);
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
            pane.Hide();
        }
        private void CreateRibbon_PipeSystemAnalysis(UIControlledApplication application)
        {
            //1.创建RibbonTab选项卡页
            application.CreateRibbonTab("义维定制");
            //2.在RibbonTab选项卡页中创建RibbonPanel面板
@@ -27,19 +91,24 @@
            //程序集路径--最好写成相对位置
            string Path1 = Assembly.GetExecutingAssembly().Location;
            //程序集的名称、所使用的类名——"主程序集命名空间.主程序类名"                                
            string Class1 = "RevitDataExport.Export";
            string Class1 = "HStation.RevitDev.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);
            string imagePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "../../../../Data/Image/analysis.png";
            push.LargeImage = new BitmapImage(new Uri(imagePath));//32 * 32
            //3.5设置命令按钮的默认提示信息
            push.ToolTip = "Revit插件简介";
        }
            return Result.Succeeded;
        private void RegistDockablePanel(UIControlledApplication uiApp)
        {
            DockablePaneId panelId = new DockablePaneId(new Guid(Common.GlobalResource.Guid_FamilyPanel));
            Wpf_FamilyPanel panel = new Wpf_FamilyPanel();
            uiApp.RegisterDockablePane(panelId, m_familyPanelName, panel);
        }
    }
}