Sub Main If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub If oADoc Is Nothing Then oADoc = ThisDoc.Document If DocEvents Is Nothing Then DocEvents = oADoc.DocumentEvents AddHandler DocEvents.OnClose, AddressOf DocEvents_OnClose Logger.Info("DocumentEvents.OnClose Event Handler Created For:" & vbCrLf & oADoc.FullDocumentName) End If If AsmEvents Is Nothing Then AsmEvents = ThisApplication.AssemblyEvents AddHandler AsmEvents.OnNewOccurrence, AddressOf AsmEvents_OnNewOccurrence Logger.Info("AssemblyEvents.OnNewOccurrence Event Handler Created") End If End Sub Dim oADoc As AssemblyDocument Dim DocEvents As DocumentEvents Dim AsmEvents As AssemblyEvents Sub DocEvents_OnClose(BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) If BeforeOrAfter = EventTimingEnum.kBefore Then RemoveHandler AsmEvents.OnNewOccurrence, AddressOf AsmEvents_OnNewOccurrence Logger.Info("AssemblyEvents.OnNewOccurrence Event Handler Removed") 'RemoveHandler DocEvents.OnClose, AddressOf DocEvents_OnClose 'Logger.Info("DocumentEvents.OnClose Event Handler Removed For:" & vbCrLf & oADoc.FullDocumentName) End If End Sub Sub AsmEvents_OnNewOccurrence(AsmDoc As AssemblyDocument, _ Occurrence As ComponentOccurrence, BeforeOrAfter As EventTimingEnum, _ Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) If AsmDoc IsNot oADoc Then Exit Sub If BeforeOrAfter = EventTimingEnum.kBefore Then ReportOnNewOccurrenceEvent(AsmDoc, Occurrence, Context, True) ElseIf BeforeOrAfter = EventTimingEnum.kAfter Then ReportOnNewOccurrenceEvent(AsmDoc, Occurrence, Context, False) End If End Sub Sub ReportOnNewOccurrenceEvent(AsmDoc As AssemblyDocument, Comp As ComponentOccurrence, Context As NameValueMap, bBefore As Boolean) Dim oSB As New System.Text.StringBuilder() If bBefore = True Then oSB.AppendLine(vbCrLf & "Before: OnNewOccurrrenceEvent") Else oSB.AppendLine(vbCrLf & "After: OnNewOccurrrenceEvent") End If oSB.AppendLine("Destination Assembly:" & vbCrLf & AsmDoc.FullDocumentName) If Comp Is Nothing Then oSB.AppendLine("New occurrence not created yet.") Else oSB.AppendLine("New occurrence name = " & Comp.Name) End If If Context.Count = 0 Then Logger.Info(oSB.ToString) Exit Sub End If oSB.AppendLine("Context:") For i As Integer = 1 To Context.Count Dim sName As String = Context.Name(i) Dim oValue As Object = Context.Value(sName) Dim sValueType As String = TypeName(oValue) If sName = "ComponentDefinition" And oValue IsNot Nothing Then Dim oCD As ComponentDefinition = oValue Dim DefDoc As Inventor.Document = Nothing Try : DefDoc = oCD.Document : Catch : End Try If DefDoc IsNot Nothing Then oSB.AppendLine("Component is referencing:" & vbCrLf & DefDoc.FullDocumentName) End If Else 'different Context entry, if any Try oSB.AppendLine("Name = " & sName) oSB.AppendLine("ValueType = " & sValueType) oSB.AppendLine("Value.ToString = " & oValue.ToString) Catch oSB.AppendLine("Error Gathering Event Context Information") End Try End If Next 'i Logger.Info(oSB.ToString) End Sub