Autodesk.Revit.UI.UIControlledApplication
是用于自定义Revit软件的UI控件应用程序类。它是一个抽象类,代表一个带有UI控件的控制台应用程序。
UIControlledApplication()
:初始化新的UIControlledApplication
实例,不包含ExternalApplication
或Application
初始化。ControlledApplication
:获取当前UIControlledApplication
实例关联的Autodesk.Revit.ApplicationServices.Application
实例。ControlledApplication.VersionName
:获取当前UIControlledApplication
实例的Revit软件版本名称。ControlledApplication.VersionBuild
:获取当前UIControlledApplication
实例的Revit软件版本的构建号。Language
:获取当前UIControlledApplication
实例的语言设置。CreateRibbonPanel(string) -> RibbonPanel
:在Revit软件中创建一个新的RibbonPanel
对象并将其添加到UI中。CreateRibbonTab(string) -> RibbonPanel
:在Revit软件中创建一个新的RibbonTab
对象并将其添加到UI中。CreateFileOpenPicker() -> FileOpenPicker
:创建FileOpenPicker
对象,用于在Revit软件中打开文件对话框。CreateFileSavePicker() -> FileSavePicker
:创建FileSavePicker
对象,用于在Revit软件中保存文件对话框。CreateMessageBox()
:创建MessageBox
对象,用于在Revit软件中显示消息框。ControlledApplicationInitialized
:当UIControlledApplication
实例完成初始化时发生。ControlledApplicationClosing
:当UIControlledApplication
实例要关闭时发生。DialogBoxShowing
:当在Revit软件中打开一个新的对话框时发生。public class MyExternalApplication : IExternalApplication
{
UIControlledApplication uiApp;
public Result OnStartup(UIControlledApplication application)
{
uiApp = application;
// 创建新的RibbonTab和RibbonPanel
var ribbonTab = uiApp.CreateRibbonTab("My Tab");
var ribbonPanel = uiApp.CreateRibbonPanel("My Panel");
// 创建新的PushButton并添加到RibbonPanel中
var pushButton = ribbonPanel.AddItem(new PushButtonData("My Button",
"My Button",
Assembly.GetExecutingAssembly().Location,
typeof(MyCommand).FullName)) as PushButton;
// 监听DialogBox显示事件
uiApp.DialogBoxShowing += HandleDialogBoxShowing;
return Result.Succeeded;
}
public void HandleDialogBoxShowing(object sender, DialogBoxShowingEventArgs args)
{
// 如果是MyCommand的消息框,则取消显示它
if (args.Message.ToLower().Contains("my message"))
{
args.OverrideResult((int)System.Windows.Forms.DialogResult.Cancel);
args.Cancel();
}
}
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
}