Please have a look at this code. It works, but only with the document that was active when the dll was loaded. What could be wrong?
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.ApplicationServices
Public Class UCS
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
Private Doc As Document
Public Sub New()
Doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
AddHandler Doc.CommandWillStart, AddressOf cmdWillStart
End Sub
Public Shared Sub cmdWillStart(ByVal o As Object, ByVal e As CommandEventArgs)
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Try
If e.GlobalCommandName = "XREF" Then
MsgBox(e.GlobalCommandName)
End If
Catch ex As Exception
ed.WriteMessage("Error in cmdWillStart: " + ex.Message)
End Try
End Sub