Before you can use application level events you must create a new class module and declare an object of type AcadApplication with events. For example, assume that a new class module is created and called EventClassModule. The new class module contains the declaration of the application with the VBA keyword WithEvents.
Public WithEvents App As AcadApplication
After the new object has been declared with events, it appears in the Object drop-down list box in the class module, and you can write event procedures for the new object in the class module. (When you select the new object in the Object box, the valid events for that object are listed in the Procedure drop-down list box.)
Before the procedures will run, however, you must connect the declared object in the class module with the Application object. You can do this with the following code from any module.
Dim X As New EventClassModule
Set X.App = ThisDrawing.Application
Once the InitializeEvents procedure has been run, the App object in the class module points to the Application object specified, and any event procedures in the class module will run when the events occur.
Cancel parameter of the BeginFileDrop event and the file is not loaded.This example intercepts the load process when a file has been dragged and dropped into AutoCAD. A message box containing the name of the file that was dropped and Yes/No/Continue buttons that allow the user to decide if the file should continue to be loaded or displayed. If the user chooses to cancel out of the operation, that decision is returned through the
Public WithEvents ACADApp As AcadApplication
' This example intializes the public variable (ACADApp)
' which will be used to intercept AcadApplication Events
' Run this procedure FIRST!
' We could get the application from the ThisDocument
' object, but that would require having a drawing open,
' so we grab it from the system.
Set ACADApp = GetObject(, "AutoCAD.Application.17")
Private Sub ACADApp_BeginFileDrop _
(ByVal FileName As String, Cancel As Boolean)
' This example intercepts an Application BeginFileDrop event.
' This event is triggered when a drawing file is dragged
' into AutoCAD.
' To trigger this example event:
' 1) Make sure to run the example that initializes
' the public variable (named ACADApp) linked to this event.
' 2) Drag an AutoCAD drawing file into the AutoCAD
' application from either the Windows Desktop
' or Windows Explorer
' Use the "Cancel" variable to stop the loading of the
' dragged file, and the "FileName" variable to notify
' the user which file is about to be dragged in.
If MsgBox("AutoCAD is about to load " & FileName & vbCrLf _
& "Do you want to continue loading this file?", _
vbYesNoCancel + vbQuestion) <> vbYes Then
Cancel = True