Events in BricsCAD VBA

= implemented   No = NOT implemented


Application Events BricsCAD AutoCAD
AppActivate

AppDeactivate

ARXLoaded

ARXUnloaded

BeginCommand

BeginFileDrop

No

BeginLisp

BeginModal

No

BeginOpen

BeginPlot

BeginQuit

BeginSave

EndCommand

EndLisp

EndModal

No

EndOpen

EndPlot

EndSave

LispCancelled

No

NewDrawing

SysVarChanged

WindowChanged


Document Events BricsCAD AutoCAD
Activate

BeginClose

BeginCommand

BeginDocClose

BeginDoubleClick

BeginLisp

BeginPlot

BeginRightClick

BeginSave

BeginShortcutMenuCommand

No (*)

BeginShortcutMenuDefault

No (*)

BeginShortcutMenuEdit

No (*)

BeginShortcutMenuGrip

No (*)

BeginShortcutMenuOsnap

No (*)

Deactivate

EndCommand

EndLisp

EndPlot

EndSave

EndShortcutMenu

No

LayoutSwitched

LispCancelled

No

ObjectAdded

ObjectErased

ObjectModified

SelectionChanged

WindowChanged

WindowMovedOrResized


Note: Events marked with (*) in list above are currently ignored. They all use the parameter ShortcutMenu (declared as AcadPopupMenu on AutoCAD and Object on BricsCAD). AcadPopupMenu is currently not implemented by BricsCAD's COM.


Object Events BricsCAD AutoCAD
Modified

Difference with AutoCAD :

Following VBA code works on AutoCAD but NOT on BricsCAD:

Option Explicit
Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
    MsgBox "AcadDocument_BeginCommand ::Command= " & CommandName
End Sub
Private Sub AcadDocument_Activate()
    MsgBox "AcadDocument_Activate"
End Sub
Private Sub AcadDocument_Deactivate()
    MsgBox "AcadDocument_Deactivate"
End Sub
  1. Above code uses events implicitly provided by AcadDocument. Within AutoCAD's VBA IDE the AcadDocument object is implicitly available : there is no need to explicitly use a WithEvents declaration or initialization.
  2. Above code follows the active drawing: when switching between drawings the document events keep working.
  3. There is no entry point or Sub Main: the events get caught as soon as the .dvb is loaded (vbaload).
  4. BricsCAD's VBA IDE also provides the AcadDocument and corresponding events drop-down list. However in BricsCAD you will need to explicitly declare (using a WithEvents clause) and initialize it in order to successfully catch events. See next section 'Keeping tabs on the Active Document'.

Keeping tabs on the Active Document :

The code below declares and initializes oDocEvents using 'WithEvents'. This oDocEvents object will implement the needed events. In our example following document events will be caught: _BeginCommand, _EndCommand,_Activate and _Deactivate.

The Sub synchDoc is responsible for keeping the oDocEvents synchronized with the currently active drawing. As you can see it gets called at several places.


Option Explicit
Public WithEvents oDocEvents As AcadDocument
Sub main()
    synchDoc
End Sub
Private Sub synchDoc()
    Dim sCurName As String: sCurName = vbNullString
    Dim sDocName As String: sDocName = vbNullString
    On Error Resume Next 'workaround oDocEvents possible Nodocument error
        sDocName = UCase(oDocEvents.Name)
        sCurName = UCase(ThisDrawing.Application.ActiveDocument.Name)
    Error 0
    If sDocName = vbNullString Then
        Set oDocEvents = ThisDrawing.Application.ActiveDocument
    End If
    If sDocName <> sCurName Then
        Set oDocEvents = ThisDrawing.Application.ActiveDocument
    End If
End Sub
Private Function logEvent(sMessage As String)
    'comment/uncomment as needed
    Debug.Print sMessage
    'MsgBox sMessage
    'ThisDrawing.Utility.Prompt sMessage
End Function
'-------DOCUMENT EVENT HANDLERS-------------
Private Sub oDocEvents_BeginCommand(ByVal CommandName As String)
    logEvent "oDocEvents_BeginCommand ::Command= " & CommandName
End Sub
Private Sub oDocEvents_EndCommand(ByVal CommandName As String)
    If CommandName = "NEW" Then synchDoc
    If CommandName = "OPEN" Then synchDoc
    logEvent "oDocEvents_EndCommand ::Command= " & CommandName
End Sub
Private Sub oDocEvents_Activate()
    logEvent "oDocEvents_Activate"
End Sub
Private Sub oDocEvents_Deactivate()
    synchDoc
    logEvent "oDocEvents_Deactivate"
End Sub


© Bricsys NV. All rights reserved.