I did a little quick testing of my own today, with some similar code, and am getting the same behavior...no kBefore reporting/responce. Here is the simple code I was using:
Class ThisRule
Dim oTargetDoc As Document
Dim oDocEvents As DocumentEvents
Sub Main
oTargetDoc = ThisDoc.Document
oDocEvents = oTargetDoc.DocumentEvents
AddHandler oDocEvents.OnClose, AddressOf oDocEvents_OnClose
Logger.Info("DocumentEvents.OnClose Event Handler Created")
End Sub
Sub oDocEvents_OnClose(oTiming As EventTimingEnum, oContext As NameValueMap, _
ByRef oHandlingCode As HandlingCodeEnum)
If oTiming = EventTimingEnum.kBefore Then
Logger.Info("DocumentEvents.OnClose Event Handler Triggered - kBefore")
If oContext.Count > 0 Then
Dim oHealthStatus As HealthStatusEnum = oContext.Value("HealthStatusEnum")
Logger.Info("HealthStatus Before: " & oHealthStatus.ToString)
End If
End If
If oTiming = EventTimingEnum.kAfter Then
Logger.Info("DocumentEvents.OnClose Event Handler Triggered - kAfter")
If oContext.Count > 0 Then
Dim oHealthStatus As HealthStatusEnum = oContext.Value("HealthStatusEnum")
Logger.Info("HealthStatus After: " & oHealthStatus.ToString)
End If
RemoveHandler oDocEvents.OnClose, AddressOf oDocEvents_OnClose
Logger.Info("Removed DocumentEvents.OnClose Event Handler")
End If
End Sub
End Class
...and here is what I get in the iLogic Logger:
INFO| 5: >>---------------------------
INFO|DocumentEvents.OnClose Event Handler Created
INFO|DocumentEvents.OnClose Event Handler Triggered - kAfter
INFO|HealthStatus After: kInErrorHealth
INFO|Removed DocumentEvents.OnClose Event Handler
Even if all I did was open a simple part, with no apparent problems, then close it again several seconds later, without doing anything to it. I also tried creating a new sketch in the part, then deleting it, just to 'dirty' the part, then close it, and say No to saving it. Same report. The official online help documentation, as well as the built-in help system documentation for this API Event say "Notification is sent before and after the document is closed." Perhaps their documentation was either copied over from some other event, and never corrected, or they have changed something and have not bothered updating the documentation about that change. Maybe someone at Autodesk would know more about this situation. I was pretty sure that I had gotten responces from both sides of that event before, but not right now.
Wesley Crihfield

(Not an Autodesk Employee)