Discussion:
Disable Events in ThisDrawing
(too old to reply)
Ted Schaefer
2004-05-06 03:40:37 UTC
Permalink
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
Tony Tanzillo
2004-05-06 06:04:28 UTC
Permalink
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
--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005
http://www.acadxtabs.com
Post by Ted Schaefer
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
Loading...