zhangyk-c
2024-07-11 9ca59ac2d37530208538a05a704b5ea712cab7db
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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;
 
namespace HStation.RevitDev.RevitDataExport.Plugin
{
    [Transaction(TransactionMode.Manual)]
    public class Application : IExternalApplication
    {
        UIControlledApplication m_uiControlledApp;
        private readonly string m_familyPanelName = "族列表";
        public Result OnShutdown(UIControlledApplication application)
        {
            return Result.Succeeded;
        }
 
        public Result OnStartup(UIControlledApplication application)
        {
            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面板
            RibbonPanel panel1 = application.CreateRibbonPanel("义维定制", "管道系统链路检测");
 
            //3.命令按钮
            //3.1指定程序集的名称、所使用的类名、程序集路径
            //程序集路径--最好写成相对位置
            string Path1 = Assembly.GetExecutingAssembly().Location;
            //程序集的名称、所使用的类名——"主程序集命名空间.主程序类名"                                
            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添加图标
            //可把图片资源加载入项目中,方便把图片的路径写成相对路径,并进行修改属性(图片的生成操作,改位:嵌入的资源)
            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插件简介";
        }
 
        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);
        }
    }
}