Hi @Anders_Olsen. I had no idea what you were planning on doing with each component just after selecting them, but attempting to get them into a collection to then run some other iLogic rule on later was not on my radar. Using the SelectSet is usually not a good fit for something like that. It has some restrictions and can be a bit finicky. Using the other collection types (ObjectCollection, List(Of ), etc) should be OK though. However, if you need a means to capture multiple objects that will stay in place between running one rule, to running another rule, then some additional strategy would be required. There are ways for one iLogic rule to 'send' data to another iLogic rule, when it calls that other rule to run. And a way to 'receive' data back from the other rule, after the other rule has finished running, if both rules are set-up to do so. (RuleArguments) There is also a way to store data from one rule up into an Inventor 'session' memory variable, where later rule(s) can later access that data from (the uniquely iLogic SharedVariable). One of the restrictions of the SelectSet is that it can only 'select' things that exist within the 'context' (definition & model coordinate space) of the Document they are associated with. For example, the SelectSet from Document A can not select something that is within Document B. And if Document A is not the 'active' document, you will not be able to use the DocumentA.SelectSet.Select() method on anything in it anyways, because true selection only works on the 'active' document. I think that may be the problem in this case also, because some of the other components that may be referencing some of the referenced documents may be down within other sub assemblies, which means they would not be in the 'context' of the 'main/active' assembly directly. With that in mind, the SelectSet object that the SelectSet.Select() method being used in that last example I posted could be switched out for something like the List(Of ComponentOccurrence) type collection instead, which may enable it to capture all the components you want. However, I still don't know how your second rule will be using them, so still not sure if the context from where they are being gathered will be the best fit either.
When iterating through assembly components (instead of just referenced documents), and wanting to do so 'recursively' (keeps stepping down into lower levels on its own), there are two ways to do that, which each work differently, as far as 'context' is concerned. When stepping down through the 'definitions' of sub assemblies to access their sub components, that is one way, but the lower level components it accesses will not be in the 'context' of the main / active assembly. When stepping down through the ComponentOccurrence.SubOccurrences collection, the association with the parent 'context' is maintained, so that the lower level components are still in the context of the main / active assembly. This second way is sort of similar to navigating through the model browser tree's nodes, with the lower level nodes still being associated with the highest level node, due to the 'tree' structure. This second way sounds like what you likely need in your situation.
Within the example code that you posted above, I see a variable misspelling or difference in how it is spelled in multiple locations ("alreadyInList" vs "alreadyOnList"). It also looks like your variable named 'occList' may not be getting properly 'initialized'. When declaring a variable for a reference type between methods, we can not initialize it or set an initial value to it until it is accessed within one of the methods. It looks like you are using the 'New' keyword directly in the declaration line, then just adding values to it within the method, without first initializing the variable. The 'New' keyword is used to initialize the List object, before entries can be added to it, but that step should be done within the method, and only when it is encountered or the first time, so avoid resetting its contents. I also see that the 'assemblyRunner' method you are using, is also being used for 'recursion' down into lower levels of the assembly, but it is doing so through the 'definitions', which does not maintain contextual lineage with the 'active' assembly. That is not necessarily a good or bad thing, depending on what you are trying to do with those components later. If you are planning on making changes to those components later, then how you gathered them will determine the 'scope' (area of effect) of the changes. If gathered through their definitions, then changes will effect the independent referenced documents. If gathered through SubOccurrences properties, then changes may only be relevant to those occurrences from the perspective of the active assembly, depending on the types of changes. For example, if you wanted to change the colors of all components in an assembly, but do not want the color changes to actually effect the files that the components reference, but only want the colors to be in effect while viewing them from within the active assembly, then you would access them through the SubOccurrences property, instead of through their definitions.
Wesley Crihfield

(Not an Autodesk Employee)