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);
|
}
|
}
|
}
|