AddAppEvent


Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
Imports System.Threading.Tasks
Imports System.Text
Imports System.Linq
Imports System.Collections.Generic
Imports System.IO
Imports System
Namespace Demo1
    Public Class Class1
        <CommandMethod("AddAppEvent")> _
        Public Sub AddAppEvent()
            Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
            AddHandler Application.SystemVariableChanged, New Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventHandler(AddressOf appSysVarChanged)
            AddHandler Application.BeginDoubleClick, New BeginDoubleClickEventHandler(AddressOf beginDoubleClick)
            AddHandler acDoc.CommandWillStart, New CommandEventHandler(AddressOf currentDoc_CommandWillStart)
            AddHandler acDoc.CommandCancelled, New CommandEventHandler(AddressOf currentDoc_CommandWillStart)
            AddHandler acDoc.CommandEnded, New CommandEventHandler(AddressOf currentDoc_CommandWillStart)
            AddHandler acDoc.CommandFailed, New CommandEventHandler(AddressOf currentDoc_CommandWillStart)
        End Sub

        <CommandMethod("RemoveAppEvent")> _
        Public Sub RemoveAppEvent()
            RemoveHandler Application.SystemVariableChanged, New Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventHandler(AddressOf appSysVarChanged)
            RemoveHandler Application.BeginDoubleClick, New BeginDoubleClickEventHandler(AddressOf beginDoubleClick)
        End Sub

        Public Sub appSysVarChanged(ByVal senderObj As Object, ByVal sysVarChEvtArgs As Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs)
            Dim oVal As Object = Application.GetSystemVariable(sysVarChEvtArgs.Name)
            ' Display a message box with the system variable name and the new value
            Application.ShowAlertDialog(sysVarChEvtArgs.Name + " was changed." + vbLf & "New value: " + oVal.ToString())
        End Sub

        Private Shared Sub beginDoubleClick(ByVal sender As Object, ByVal e As BeginDoubleClickEventArgs)
            Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
            Dim strDWGName As String = acDoc.Name
            Application.ShowAlertDialog(strDWGName)
        End Sub

        Private Sub currentDoc_CommandWillStart(ByVal sender As Object, ByVal e As CommandEventArgs)
            'Application.ShowAlertDialog(e.GlobalCommandName);
            Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
            Dim strDWGName As String = acDoc.Name
            Application.ShowAlertDialog(strDWGName)
        End Sub
    End Class
End Namespace



VS2012



欢迎关注微信公众账号ByCAD