OK. Was there any error messages? If not, it may be because I use Try...Catch...End Try statements a lot where something might fail, but since I was in a hurry, I did not incorporate any feedback messages or Log entries on the 'Catch' sides of them in that code example.
One thing that comes to mind is the 'IsModifiable' property check just inside my 'ChangeModelStateOfDerivedPart' Sub routine. If that is False, then it would have just skipped over that document. This can often be False simply because it is seen as a 'ModelState member', if the component is referencing a model file that has multiple ModelStates in it. If this is true, then it may be skipping nearly all of them. There needs to be a better, or more accurate property for checking this type of status.
On top of that, I do not believe that if the 'host' part has multiple ModelStates in it, that the currently active ModelState in that 'host' part (the part with the other one derived into it) will record, or have any control over, which ModelState the 'source' part (the part that is being derived into the other) is set to within the derive settings.
Does the 'source' part have all the same ModelStates in it that the 'host' part has in it?
Would it be OK to include instructions within the code to update the main assembly between where the code works on each component or referenced document? This can be pretty slow in really large assemblies, but not so bad in smaller ones. It may be needed though in situations where there are a lot of ModelStates being used in assemblies. The link below to an online help page describes this situation a little bit, but only provides a very brief example code.
To Modify an Occurrence Parameter with a Model State
We may have to start with a smaller, simpler code that you can try running from within the part itself, just to make sure the core code for changing which ModelState the 'derived in' source model is set to within the derive settings is working OK for you. Once that is established, we can try modifying the custom Sub routine in my code to work around that 'IsModifiable' issue. Essentially what needs to happen in that code is to get a copy of the existing DerivedPartDefinition object, then change that property value (ActiveModelState), then set that DerivedPartDefinition object back as the new value of DerivedPartComponent.Definition property. Then probably update the part it is derived into.
Wesley Crihfield

(Not an Autodesk Employee)