Q: I would like to get informed when the user enters/exits Sketch edit mode. Which event should I subscribe for?
A: You have 3 ways to check if you are in Sketch Edit mode.
You can use either...
1. Application.ActiveEditObject or
2. Document.ActivatedObject or perhaps
3. Application.ActiveEnvironment
Function isAnyModelInSketchEditMode()
isAnyModelInSketchEditMode = False
Dim oDoc As Document
For Each oDoc In ThisApplication.Documents
If Not oDoc.ActivatedObject Is Nothing Then
If TypeOf oDoc.ActivatedObject Is Sketch Then
isAnyModelInSketchEditMode = True
Exit Function
End If
End If
Next
End Function
Getting informed of the edit mode change can be based on the first object's change (Application.ActiveEditObject).
Option Explicit
Dim WithEvents oApplicationEvents As ApplicationEvents
Dim bWasInSketchMode As Boolean
Private Sub Class_Initialize()
Set oApplicationEvents = ThisApplication.ApplicationEvents
End Sub
Private Sub oApplicationEvents_OnNewEditObject( _
ByVal EditObject As Object, _
ByVal BeforeOrAfter As EventTimingEnum, _
ByVal Context As NameValueMap, _
HandlingCode As HandlingCodeEnum)
If BeforeOrAfter = kAfter Then
If TypeOf EditObject Is Sketch Then
MsgBox "We've just entered Sketch edit mode!"
ElseIf bWasInSketchMode Then
MsgBox "We've just exited Sketch edit mode!"
End If
ElseIf BeforeOrAfter = kBefore Then
If TypeOf ThisApplication.ActiveEditObject Is Sketch Then
bWasInSketchMode = True
Else
bWasInSketchMode = False
End If
End If
End Sub