Hi @Darkforce_the_ilogic_guy. That is a bit difficult to review and understand, but I definitely saw some error prone areas in it. Since I already had a couple saved snippets in my iLogic toolbox from helping a couple other people out with similar requests, I decided that it might be easier for me to start from one of those examples, then modify it as needed, than attempt to fix your current example code. Although the concept of this task seems very simple, it is not actually that simple to make happen automatically, entirely by code in a comprehensive way that would work without any errors or problems. There are simply some situations which are difficult or impossible to deal with. It is possible that some documents involved are ReadOnly, such as Content Center or 'Library' stuff, and various others. When that is the case, their Document.DisplayName can not be changed. When a component is suppressed, there is not much we can do with it, or the document it references, without throwing errors, because a lot of the data associated with it are unloaded from Inventor's memory, for performance reasons. Sometimes, if there are multiple instances / occurrences referencing multiple different ModelState versions of the same source file, that means that there are multiple 'Documents' being held in Inventor's memory, which all reference back to the same file on disk, and we will not be able to modify some of those Documents the way we want. Then there is the simple fact that no two component occurrences in an assembly can have exactly the same name. So, if 4 occurrences all reference a Document with the same Part Number value, we can not simply name all 4 of those occurrences that Part Number value. There has to be some sort of naming convention with a 'sequential' aspect to it, to make each of them unique. Inventor usually handles that stuff automatically for us by putting the colon character (:) then an Integer as an index number after each instance that references the same source file, but that does not happen automatically when doing things by code.
Attached is a text file containing the code for a very long iLogic rule with several separate methods involved. I chose to employ a strategy of using a Dictionary to bundle components by the Part Number value of the documents they reference. That way all the ones with the same Part Number value can be renamed in a controlled sequence, with an Integer type Index system. You can change how that system works if you want to, but this is just an example of how it could be done. You can give that rule a try if you want, or just review its contents for ideas about how to potentially fix your current code example. I have not tested it yet myself, because I have no use for it, and do not want to change any of my files in those ways. I hope this helps some.
Wesley Crihfield

(Not an Autodesk Employee)