Hi guys.
@Joseph.Lasser Another little trick that may help in a situation like this would be to 'stabilize' the component names within the model browser tree. This is done by modifying each occurrence's name to something different than its 'default' value (default value is usually file name, but can also be switched to part number), but is still unique, and still lets you identify which occurrence it is. When you do this, then when you replace that occurrence with another source file, that action will not change that occurrence's name. When that is the case, then you can always find that exact occurrence by its name within your iLogic rules, without having to worry about their names changing. There are multiple forum discussions about this idea / tactic, and some folks have their own personal Blog sites which have good articles about this tactic / strategy.
Below is just another example which iterates all referenced documents, similar to @marcin_otręba example, but is laid out a bit different, and includes a couple different methods or techniques. For example, it is using the 'iLogicVb.Automation.RunRule(document, ruleName) method , instead of the iLogicVb.RunRule(Object, String) method, because it allows us to specify the Document object that we want that rule to target, since we already have access to that object available within the iteration of referenced documents. And it utilizes a Try...Catch...Finally...End Try statement, to help allow the rule to continue running, even if an error is encountered somewhere along the way. I tried to include plenty of comments within the code, since you are not that familiar with these things yet. This is just one possibility among a great many possible ways that a rule like this could be formatted or laid out. Another idea would be to get the actual internal rule objects within those referenced documents, then use the iLogicVb.Automation.RunRuleDirect(rule As iLogicRule) method to run them. This just another way to help ensure that the rule being ran is sourced from that exact Document, and effecting that exact Document, as intended. These extra tactics are sometimes necessary, because when a rule gets ran, and the main assembly is still the 'active' document at that time, to help the rule to target the referenced document, instead of the active assembly document. The code within each of those internal rules also matters, because they may be trying to access or work with the 'active' document, instead of the Document which that rule is within. Using specific Document references becomes very important when the rules may get ran 'remotely' like this (while another Document is 'active', or because an event happened).
'capture the current document to a variable
Dim oDoc As Inventor.Document = ThisDoc.Document
'get all referenced documents from all levels to one variable
Dim oRefDocs As DocumentsEnumerator = oDoc.AllReferencedDocuments
'check if there were no referenced documents, and if so exit this rule
If oRefDocs Is Nothing OrElse oRefDocs.Count = 0 Then Return
'get the iLogic Automation object to a variable
Dim oAuto As IiLogicAutomation = iLogicVb.Automation
'start iterating through each referenced document
For Each oRefDoc As Inventor.Document In oRefDocs
'get 'FullFileName' (full path, file name, & extension) of this document
Dim sFFN As String = oRefDoc.FullFileName
'extract just file name (no path, no extension) from FullFileName
Dim sFileNameWOExt As String = System.IO.Path.GetFileNameWithoutExtension(sFFN)
'now check this file name to determine which rules to run on it
'first check is if it starts with the upper-case letter "A"
If sFileNameWOExt.StartsWith("A") Then
'using a Try...Catch...Finally...End Try statement below
'this will 'try' to do something that might cause an error
'but if it does cause an error, it will not stop the whole rule
'and will allow the rule to keep going. (just in case its needed)
Try 'code to try goes in first section
'second check what it ends with (remember, no file extensions here)
If sFileNameWOExt.EndsWith("-TREAD") Then
'if passed both checks, then run rules on that Document
'this method lets us specify the actual Document object for the rule to target
oAuto.RunRule(oRefDoc, "Spreadsheet Link")
'oAuto.RunRule(oRefDoc, "Document Update")
ElseIf sFileNameWOExt.EndsWith("-REF") Then
oAuto.RunRule(oRefDoc, "Spreadsheet Link")
'oAuto.RunRule(oRefDoc, "Document Update")
ElseIf sFileNameWOExt.EndsWith("-SS01") Then
'oAuto.RunRule(oRefDoc, "Document Update")
ElseIf sFileNameWOExt.EndsWith("-SS02") Then
'oAuto.RunRule(oRefDoc, "Document Update")
End If
Catch ex As Exception
'This section only runs if 'Try' section caused error
'the 'ex' variable captures the actual Error Object
'next line writes info about error to the iLogic Log window
Logger.Error(ex.ToString)
End Try 'end of 'EndsWith' check
End If 'end of 'StartsWith' check
Next 'go to next referenced document, if any
'iteration of referenced documents is done at this point
oDoc.Rebuild2(True)
'oDoc.Save()
Wesley Crihfield

(Not an Autodesk Employee)