Author Topic: Accessing and "executing" application level events  (Read 2511 times)

0 Members and 1 Guest are viewing this topic.

ML

  • Guest
Accessing and "executing" application level events
« on: May 08, 2006, 10:12:38 PM »

Hi,

I am able to access The app level events, however, I can not get the events to trigger. VBA is initialzing when I start ACAD, so that is not the problem, but I am not sure what to do next.

Thanks

Mark

Chuck Gabriel

  • Guest
Re: Accessing and "executing" application level events
« Reply #1 on: May 09, 2006, 08:15:02 AM »
Application-level events aren't quite as convenient as document-level events.

Perhaps some sample code will help.

In a standard module:

Code: [Select]
Option Explicit

Public appEvents As clsAppEvents

Sub Initialize()
  ThisDrawing.SetVariable "FILEDIA", 1
  If appEvents Is Nothing Then
    Set appEvents = New clsAppEvents
  End If
End Sub

Sub Terminate()
  Set appEvents = Nothing
End Sub

In a class module called clsAppEvents:

Code: [Select]
Private WithEvents m_objApp As AcadApplication

Private Sub Class_Initialize()
  Set m_objApp = ThisDrawing.Application
End Sub

Private Sub Class_Terminate()
  Set m_objApp = Nothing
End Sub

Private Sub m_objApp_SysVarChanged(ByVal SysvarName As String, ByVal newVal As Variant)

  If SysvarName = "FILEDIA" Then
    If newVal = 0 Then
      If StrComp(ThisDrawing.GetVariable("CMDNAMES"), "SETVAR", vbTextCompare) <> 0 Then
        ThisDrawing.SetVariable "FILEDIA", 1
      End If
    End If
  End If

End Sub

You have to manually call the Initialize subroutine located in the standard module for this to work.