I've been working to solve this and thought I had it but have run into an issue.
The goal of all this is that when this specific assembly document type is opened, it waits for a new occurrence, and runs the rule "Material AutoFill". "Material AutoFill" will take the last part occurrence and place that part's name into a custom iProperty of the current assembly file.
I created an internal rule inside the specific template called "event trigger" using handlers. This rule triggers on a new document or open document, so anytime a new or existing assembly of this type is created/opened the handler runs.

The "event trigger" code is below:
Sub Main
Dim oAsmEvents As AssemblyEvents = ThisApplication.AssemblyEvents
AddHandler oAsmEvents.OnNewOccurrence, AddressOf oAsmEvents_OnNewOccurrence
Dim oAppEvents As ApplicationEvents = ThisApplication.ApplicationEvents
AddHandler oAppEvents.OnCloseDocument, AddressOf ApplicationEvents_OnCloseDocument
End Sub
Public Sub oAsmEvents_OnNewOccurrence(oAsmDoc As AssemblyDocument, oOcc As ComponentOccurrence, oTiming As Inventor.EventTimingEnum, oContext As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum)
If oTiming = kAfter Then
iLogicVb.RunRule("Material AutoFill")
End If
End Sub
Public Sub ApplicationEvents_OnCloseDocument(oDoc As Inventor._Document, oFullName As String, oTiming As Inventor.EventTimingEnum, oContext As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum)
If oDoc Is ThisDoc.Document Then
Dim oAsmEvents As AssemblyEvents = ThisApplication.AssemblyEvents
Dim oAppEvents As ApplicationEvents = ThisApplication.ApplicationEvents
RemoveHandler oAsmEvents.OnNewOccurrence, AddressOf oAsmEvents_OnNewOccurrence
RemoveHandler oAppEvents.OnCloseDocument, AddressOf ApplicationEvents_OnCloseDocument
End If
End Sub
The autofill rule is a separate internal rule that looks through all occurrences, and takes the last one and places it into the custom iProperty field.
The "Material AutoFill" code:
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
Dim oName As String
oName = Left(oOccurrence.Name, 9)
iProperties.Value("Custom", "Material2") = oName
Next
This has worked exactly as I wanted until I started working in higher level assemblies. If I open a higher level assembly that contains one of the assemblies with these rules, the handler will run and any new occurrences in the higher level assembly will trigger the rules. The higher level assembly in these cases does not contain either of the rules above.
I only want the rules to trigger when that specific document is worked on, and only when that specific document sees a new occurrence.
Any thoughts on how to address this?