AutoCAD 始终在打开新文档或现有文档的情况下启动。但是,可以在本届会议期间关闭所有文件。 如果关闭AutoCAD用户界面中的所有文档,则会注意到应用程序窗口的一些更改。“快速访问”工具栏和“应用程序”菜单提供的选项有限。这些有限的选项与创建和打开图形、显示图纸集管理器以及恢复图形有关。如果显示菜单栏,还会显示简化的“文件”、“视图”、“窗口”和“帮助”菜单。您还会注意到没有命令行。 在零文档状态下工作时,可以执行以下操作:
要在AutoCAD进入零文档状态时对AutoCAD做出反应,应使用该事件。关闭打开的文档时会触发该事件。当最后一个文档关闭时,文档计数将为 1。使用 的属性可确定触发事件时打开的文档数。DocumentDestroyedDocumentDestroyedCountDocumentManagerDocumentDestroyed 自定义应用程序菜单此示例代码使用该事件来监视最后一个图形何时关闭以及何时输入零文档状态。输入零文档状态后,该事件将注册到应用程序菜单中。单击应用程序菜单时,将触发该事件。在活动期间,应用程序菜单中会添加一个新的菜单项。新菜单项将显示一个消息框。DocumentDestroyedOpeningOpeningOpening 注意:您必须引用项目的AdWindows.dll才能使用以下示例代码。AdWindows.dll包含用于自定义应用程序菜单的命名空间,可以在 AutoCAD 的安装文件夹或 ObjectARX SDK 的一部分中找到。您还需要参照,该参照可在“添加参照”对话框的“AutoCAD .NET”选项卡上找到。WindowsBase
VB.NETImports System.Windows.Input Imports Autodesk.Windows Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices '' Create the command handler for the custom application menu item Public Class MyCommandHandler Implements ICommand Event CanExecuteChanged(ByVal sender As Object, ByVal e As EventArgs) _ Implements ICommand.CanExecuteChanged Function CanExecute(ByVal parameter As Object) As Boolean _ Implements ICommand.CanExecute Return True End Function Sub Execute(ByVal parameter As Object) Implements ICommand.Execute Application.ShowAlertDialog("MyMenuItem has been clicked") End Sub End Class Public Class Chapter4 ''Global var for ZeroDocState Dim acApMenuItem As ApplicationMenuItem = Nothing <CommandMethod("AddZeroDocEvent")> _ Public Sub AddZeroDocEvent() '' Get the DocumentCollection and register the DocumentDestroyed event Dim acDocMgr As DocumentCollection = Application.DocumentManager AddHandler acDocMgr.DocumentDestroyed, AddressOf docDestroyed End Sub Public Sub docDestroyed(ByVal obj As Object, _ ByVal acDocDesEvtArgs As DocumentDestroyedEventArgs) '' Determine if the menu item already exists and the number of documents open If Application.DocumentManager.Count = 1 And IsNothing(acApMenuItem) Then '' Add the event handler to watch for when the application menu is opened '' AdWindows.dll must be referenced to the project AddHandler ComponentManager.ApplicationMenu.Opening, _ AddressOf ApplicationMenu_Opening End If End Sub Public Sub ApplicationMenu_Opening(ByVal sender As Object, _ ByVal e As EventArgs) '' Check to see if the custom menu item was added previously If IsNothing(acApMenuItem) Then '' Get the application menu component Dim acApMenu As ApplicationMenu = ComponentManager.ApplicationMenu '' Create a new application menu item acApMenuItem = New ApplicationMenuItem() acApMenuItem.Text = "MyMenuItem" acApMenuItem.CommandHandler = New MyCommandHandler() '' Append the new menu item acApMenu.MenuContent.Items.Add(acApMenuItem) '' Remove the application menu Opening event handler RemoveHandler ComponentManager.ApplicationMenu.Opening, _ AddressOf ApplicationMenu_Opening End If End Sub End Class C#using Autodesk.Windows; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; // Create the command handler for the custom application menu item public class MyCommandHandler : System.Windows.Input.ICommand { public bool CanExecute(object parameter) { return true; } public event EventHandler CanExecuteChanged; public void Execute(object parameter) { Application.ShowAlertDialog("MyMenuItem has been clicked"); } } class Chapter4 { //Global var for ZeroDocState ApplicationMenuItem acApMenuItem = null; [CommandMethod("AddZeroDocEvent")] public void AddZeroDocEvent() { // Get the DocumentCollection and register the DocumentDestroyed event DocumentCollection acDocMgr = Application.DocumentManager; acDocMgr.DocumentDestroyed += new DocumentDestroyedEventHandler(docDestroyed); } public void docDestroyed(object obj, DocumentDestroyedEventArgs acDocDesEvtArgs) { // Determine if the menu item already exists and the number of documents open if (Application.DocumentManager.Count == 1 && acApMenuItem == null) { // Add the event handler to watch for when the application menu is opened // AdWindows.dll must be referenced to the project ComponentManager.ApplicationMenu.Opening += new EventHandler<EventArgs>(ApplicationMenu_Opening); } } void ApplicationMenu_Opening(object sender, EventArgs e) { // Check to see if the custom menu item was added previously if (acApMenuItem == null) { // Get the application menu component ApplicationMenu acApMenu = ComponentManager.ApplicationMenu; // Create a new application menu item acApMenuItem = new ApplicationMenuItem(); acApMenuItem.Text = "MyMenuItem"; acApMenuItem.CommandHandler = new MyCommandHandler(); // Append the new menu item acApMenu.MenuContent.Items.Add(acApMenuItem); // Remove the application menu Opening event handler ComponentManager.ApplicationMenu.Opening -= new EventHandler<EventArgs>(ApplicationMenu_Opening); } } } 父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:37
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.