PDA

View Full Version : CommandEnded Event



KevinBarnett
2006-01-27, 08:20 AM
I need to write a program that performs actions at the end of certain commands. To this end I have written the following code. The code should at least message "Kilroy was here" but it doesnt (although, what I really need is name of the command that just ended).
What is missing?
Thx.
Kevin.

Imports System
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.GraphicsInterface

Public Class Class1
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication

Private CurrentDoc As Document

Private Shared Sub m_doc_Commandended(ByVal sender As System.Object, _
ByVal e As Autodesk.AutoCAD.ApplicationServices.CommandEventArgs)
Dim curdb As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = curdb.TransactionManager
Dim myT As Transaction = tm.StartTransaction()
MsgBox("Kilroy was here")
Try
MsgBox(sender.ToString)
Catch ex As Exception
myT.Abort()
MsgBox(ex.Message.ToString)
Finally
myT.Dispose()
End Try
End Sub

KevinBarnett
2006-01-30, 09:52 AM
Filipe sent me a solution on the autodesk discussion group. Code included below. But the loaded function only functions in the drawing that was active when NETLOAD was executed. Is there an AutoCAD setting to enable netload across all drawings or must the code be changed?

Imports System
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.GraphicsInterface

Public Class Class1

Implements Autodesk.AutoCAD.Runtime.IExtensionApplication

Private CurrentDoc As Document

Public Sub New()
CurrentDoc = Application.DocumentManager.MdiActiveDocument
AddHandler CurrentDoc.CommandEnded, AddressOf m_doc_CommandEnded
End Sub

Private Shared Sub m_doc_CommandEnded(ByVal sender As System.Object, _
ByVal e As Autodesk.AutoCAD.ApplicationServices.CommandEventArgs)
MsgBox("Kilroy was here!")
msgbox(e.GlobalCommandName)
End Sub