I'm missing something with the

Discussion in 'AutoCAD' started by Steel.Detailer, Jan 12, 2004.

  1. I've been trying to figure out how to use the "BeginQuit" event with little success. I'm a novice at VBA in AutoCad, so please don't go too fast!! I've tried to follow the instructions in the "VBA help", but seem to be missing something....

    I've created a Class Module called "EventClassModule" and have the following code in it:

    Public WithEvents ACADApp As AcadApplication
    Public WithEvents AcadDocument As AcadDocument

    I've put the tried the following code in both the "this drawing" object and a module called "module1" (not at the same time):

    Sub AcadApplication_Events()
    ' This example intializes the public variable (ACADApp) which will be used
    ' to intercept AcadApplication Events
    '
    ' The VBA WithEvents statement makes it possible to intercept an generic object
    ' with the events associated with that object.
    '
    ' Before you will be able to trigger any of the AcadApplication events,

    ' you will first need to run this procedure.

    ' 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")
    End Sub
    Private Sub ACADApp_BeginQuit(Cancel As Boolean)
    ' This example intercepts an Application BeginQuit event.

    '
    ' This event is triggered when AutoCAD receives a request to shut down.
    '
    ' To trigger this example event:
    ' 1) Make sure to run the example that initializes
    ' the public variable (named ACADApp) linked to this event.
    '
    ' 2) Close the AutoCAD application

    ' Use the "Cancel" variable to stop the shut down of the application
    If MsgBox("AutoCAD is about to shut down. Do you want to continue with the shutdown?", vbYesNoCancel + vbQuestion) <> vbYes Then

    Cancel = True
    End If
    End Sub

    It doesn't seem to work either way. the "AcadApplication_Events" sub says that "this has to be run first".....how do I do that? I suspect this may be my problem, but.....

    Thanks in Advance!!!

    Rich
     
    Steel.Detailer, Jan 12, 2004
    #1
  2. Try this.

    Put the following in a new empty standard module:

    Option Explicit

    Public g_objAppEvents As clsAppEvents

    Sub Initialize()
    Set g_objAppEvents = New clsAppEvents
    End Sub

    Sub Terminate()
    Set g_objAppEvents = Nothing
    End Sub


    Then put the following in a new empty class module and name the class module
    clsAppEvents:

    Option Explicit

    Private WithEvents m_objApp As AcadApplication

    Private Sub Class_Initialize()
    Set m_objApp = Application
    End Sub

    Private Sub m_objApp_BeginQuit(Cancel As Boolean)
    MsgBox "About to quit."
    Cancel = True
    End Sub


    Then run the Sub in the standard module called Initialize. Make sure to run the
    terminate sub when you are done, or you won't be able to quit AutoCAD.
    success. I'm a novice at VBA in AutoCad, so please don't go too fast!! I've
    tried to follow the instructions in the "VBA help", but seem to be missing
    something....
    module called "module1" (not at the same time):
    "this has to be run first".....how do I do that? I suspect this may be my
    problem, but.....
     
    Chuck Gabriel, Jan 12, 2004
    #2
  3. Chuck,

    That's the closest I've gotten, but still can't quite get to what I want done. Myabe you can find the error in my thinking....

    When I quit AutoCAD, I want to make sure a profile is always set to "Plain AutoCAD". I may start AutoCAD with one of several profiles "current" by means of the "/p" switch in the shortcut (I have several shortcuts on my desktop).

    So, I want to run "initialize" as soon as a drawing opens. When I quit, I want to set "Plain AutoCAD" to the current profile and end AutoCAD after the prompt to save the drawing.

    All help appreciated.......

    Rich
     
    Steel.Detailer, Jan 12, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.