Disable Events in ThisDrawing

Discussion in 'AutoCAD' started by Ted Schaefer, May 6, 2004.

  1. Ted Schaefer

    Ted Schaefer Guest

    I was using the built-in AcadDocument (AcadDocument_BeginCommand and
    added AcadDocument_EndCommand, etc). I also declared
    oDwg as an AcadDocument withevents. I found that if I didn't have
    matching Subs for both document objects, the AcadDocument
    would stop triggering on events. On a bigger version of this routine,
    I got it all working without the shadow functions, but if I did a "saveas"
    to a new dvb file, the events would stop.

    The problem started when I added AcadDocument_EndCommand
    without adding the shadow, oDwg _EndCommand, even though I had
    no reason to use it.

    If curious, you can comment out the oDwg Subs and see the matching
    AcadDocument subs stop working. This was a real hair puller.

    If anyone can verify this or offer an explanation why this is true, I'd like
    to know.

    Cheers, Ted Schaefer


    Option Explicit

    Public WithEvents oDwg As AcadDocument

    Public Sub acadstartup()
    Set oDwg = ThisDrawing
    End Sub

    Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
    Debug.Print "BgCmd: " & CommandName
    End Sub

    Private Sub AcadDocument_BeginSave(ByVal FileName As String)
    Debug.Print "BgSv: " & FileName
    End Sub

    Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
    Debug.Print "EndCmd: " & CommandName
    End Sub

    Private Sub oApp_BeginSave(ByVal FileName As String)
    End Sub

    Private Sub oDwg_BeginCommand(ByVal CommandName As String)
    Debug.Print "BgCmd2: " & CommandName
    End Sub

    Private Sub oDwg_BeginSave(ByVal FileName As String)
    Debug.Print "BgSv2: " & FileName
    End Sub

    Private Sub oDwg_EndCommand(ByVal CommandName As String)
    Debug.Print "EndCmd2: " & CommandName
    End Sub
     
    Ted Schaefer, May 6, 2004
    #1
  2. ThisDrawing is quite different from a variable
    declared as AcadDocument. The ThisDrawing variable
    is _always_ assigned to the Active document.

    AutoCAD's VBA system automatically reassigns the value
    of ThisDrawing to the active document when its activated,
    so your oDwg variable is not always associated with the
    Active document, rather it is assigned to the document
    that was active when your acadStartup sub was called.

    Try adding this:

    Private Sub AcadDocument_Activate()
    Set oDoc = ThisDrawing
    End Sub
     
    Tony Tanzillo, May 6, 2004
    #2
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.