If your drawing document only has one model document being represented within it, you should be able to use this line to get the model file: (the single model document can be either a Part or an Assembly)
Dim oMDoc As Document = ThisDrawing.ModelDocument
But, if your drawing document is showing multiple different model documents, we will have to loop through each DrawingView and get the model document being represented within each view.
Another thing I still don't know is if your 'older' model documents already contain the needed rules that you wish to add to the model's Event Triggers. If the target rules aren't already in the older model files, then where are the rules you are wanting to add to the Event Triggers of the model file; or how do you plan to supply/specify which rules to add to the model's event triggers?
The following iLogic rule assumes the active drawing document is only representing a single model document, and that the target rules are already within the model document. You just need to edit this code to change the names of the model rules you want it to add to the model's Event Triggers. Right now I'm just specifying 3 generic rule names, but you can have as many as 99 or as few as 1. If you only need to add 1 rule, you can get rid of the List object and the loop through the List's contents.
This rule also assumes you don't need to preserve any existing Event Triggers settings, because it deletes the existing property set that contains those setting (if they exist), then recreates that property set. Then it adds each of your specified rule names to the 'BeforeDocSave' event.
So...if you run the following rule as an external rule, while the drawing document is active, it will get the model document, get its Event Triggers property set, then add the rule names (specified within this rule) to the BeforeDocSave event of the event triggers of the model file. If any of those rules don't exist within the model file, it will let you know then exit the rule.
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oMDoc As Document = ThisDrawing.ModelDocument
Dim oRuleNames As New List(Of String)
oRuleNames.Add("First Rule Name") '<<<<<<<!!! EDIT THIS RULE NAME !!! >>>>>>>>>
oRuleNames.Add("Second Rule Name") '<<<<<<<!!! EDIT THIS RULE NAME !!! >>>>>>>>>
oRuleNames.Add("Third Rule Name") '<<<<<<<!!! EDIT THIS RULE NAME !!! >>>>>>>>>
'Making sure those rules exist within the model document
Dim oAuto As IiLogicAutomation = iLogicVb.Automation
Dim oRule As iLogicRule
Dim oRuleName As String
For Each oRuleName In oRuleNames
Try
oRule = oAuto.GetRule(oMDoc, oRuleName)
Catch
MsgBox("The rule named " & oRuleName & " was not found within the model document. Exiting.", vbOKOnly + vbCritical, " ")
Exit Sub
End Try
Next
'Getting the Event Triggers iProperty set
Dim oEventsPropSet As Inventor.PropertySet
Dim oSetName As String = "iLogicEventsRules"
Dim oInternalName As String = "{2C540830-0723-455E-A8E2-891722EB4C3E}"
Try
oEventsPropSet = oMDoc.PropertySets.Item(oSetName)
Catch
oEventsPropSet = oMDoc.PropertySets.Item("_" & oSetName)
End Try
If oEventsPropSet IsNot Nothing Then
oEventsPropSet.Delete
oEventsPropSet = oMDoc.PropertySets.Add(oSetName, oInternalName)
Else
oEventsPropSet = oMDoc.PropertySets.Add(oSetName, oInternalName)
End If
'Define the event's PropId range
Dim oRangeStart As Integer = 700
Dim oRangeEnd As Integer = 799
Dim oPropId As Integer = oRangeStart
'Start adding the rule names to the event triggers
For Each oRuleName In oRuleNames
If oPropId <= oRangeEnd Then
oEventsPropSet.Add(oRuleName, "BeforeDocSave" & oPropId.ToString, oPropId)
Else
MsgBox("You've reached the maximum number of rules you can add under this event. Exiting.", vbOKOnly, " ")
Exit Sub
End If
oPropId = oPropId + 1
Next
Exit Sub
I also have multiple resources available dealing with the (hidden by default) Event Triggers property set.
In these resources I attempt to explain how everything works and how to do it yourself using iLogic code.
One shows how to 'Un-Hide' this set.
Another shows how to find & inspect an existing property set to confirm table data, then how to add a single rule to it.
Another shows how to copy all local iLogic rules as well as the Event Triggers settings from one document to another.
Another post, that may help with the situation of working with older documents, shows how to use an external iLogic rule to create & place local iLogic rules within other documents.
Also, FYI @jzcrouse:
Within those reference posts you'll find a table which shows updated data about which events use which PropId ranges. I built this as an Excel spreadsheet from personal research and testing, instead of copying from old posts. One of the main differences is the 'AfterDrawingViewsUpdate' event. The older posts show it using the 1500 to 1599 range, but my testing shows this range to actually be 1800 to 1899. This data was captured from actually adding multiple rules to each of the different types of events within all the different types of documents, then afterwards, capturing all the data from the resulting property set and all its properties. Each time you edit or update a 'Contribution' post, it updates the main date on the post, and you'll see that all these posts have been recently updated with the latest findings. I don't recall exactly when the 'AfterDrawingViewsUpdate' event changed from using the 1500's to the 1800's, though due to having skipped over an Inventor release here and there and having had multiple Autodesk Accounts over the years.
Wesley Crihfield

(Not an Autodesk Employee)