Sub Main '<<< get a reference to the Document that this rule should focus on >>> Dim oDoc As Document = ThisDoc.Document '<<< this creates a List for storing String type values >>> Dim oExternalRuleNames As New List(Of String) '<<< EDIT THESE EXTERNAL RULE NAMES >>> '<<< DO NOT ADD "file://" TO THEIR NAMES HERE, THAT WILL BE DONE LATER >>> oExternalRuleNames.Add("First External Rule Name") oExternalRuleNames.Add("Second External Rule Name") oExternalRuleNames.Add("Third External Rule Name") '<<< the Internal Name of the Event >>> Const sEventInternalName As String = "BeforeDocSave" '<<< the starting value for the PropID range valid for this specific event >>> Dim iPropIDRangeStart As Integer = 700 '<<< a variable to represent the last PropId value in the range >>> Dim iPropIDEnd As Integer = (iPropIDStart + 99) '<<< the 'prefix' needed before the names of external iLogic rules >>> Const sExternalRulePrefix As String = "file://" '<<< the 'ClientId' of the iLogic ApplicationAddIn object >>> Const iLogicClientId As String = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}" '<<< name of a possible temporary internal iLogic rule >>> Const sTempInternalRuleName As String = "DeleteMe" '<<< prepare a variable to possibly hold a temporary internal iLogic rule object >>> Dim oTempRule As iLogicRule = Nothing '<<< check if this Document is 'prepared' for this type of editing, and if not prepare it >>> If oDoc.DocumentInterests.HasInterest(iLogicClientId) = False Then '<<< add an empty, temporary, internal iLogic rule to this Document, to prepare it >>> oTempRule = iLogicVb.Automation.AddRule(oDoc, sTempInternalRuleName, "") End If '<<< a variable to hold the hidden PropertySet which contains the Event Triggers settings, if any >>> Dim oSet As PropertySet = Nothing '<<< the regular default name of this hidden PropertySet >>> Const sSetName As String = "_iLogicEventsRules" '<<< the default Internal Name of this hidden PropertySet (its primary identification) >>> Const sSetInternalName As String = "{2C540830-0723-455E-A8E2-891722EB4C3E}" '<<< try to find this hidden PropertySet, by its Internal Name, if it exists >>> If Not oDoc.PropertySets.PropertySetExists(sSetInternalName, oSet) Then '<<< If it did not exist, then create it >>> oSet = oDoc.PropertySets.Add(sSetName, sSetInternalName) End If '<<< iterate each external iLogic rule name in the List above >>> For Each sRuleName In oExternalRuleNames '<<< add the needed prefix before each external iLogic rule name >>> sRuleName = sExternalRulePrefix & sRuleName '<<< a variable to hold the Property object >>> Dim oProp As Inventor.Property = Nothing '<<< iterate PropId values in this range >>> For iPropID As Integer = iPropIDStart To iPropIDEnd 'check if a Property object exists with this PropId Try : oProp = oSet.ItemByPropId(iPropID) : Catch : End Try If oProp Is Nothing Then 'no Property was found at this PropId, and no Property was found for this Rule yet Try 'try to create a Property for this rule, using this PropId oProp = oSet.Add(sRuleName, sEventName & iPropID, iPropID) Exit For 'exit loop of PropId range, then go to next rule name, if any Catch : End Try Else 'a Property with this PropId was found, so check its Value for this rule's name If oProp.Value = sRuleName Then 'existing Property found for this rule Exit For 'exit loop of PropId values, and go to next rule name Else 'a Property with this PropId exists, but its Value is a different rule name Continue For 'skip to next PropId value in range (same rule name) End If End If Next 'go to next PropID to check it, if any Next 'sRuleName '<<< if a temporary internal iLogic rule was added to this Document for preparation, remove it now >>> If oTempRule IsNot Nothing Then iLogicVb.Automation.DeleteRule(oDoc, sTempInternalRuleName) End If '<<< update this document immediately - may not be necessary >>> oDoc.Update2(True) '<<< save this document >>> 'oDoc.Save End Sub