Load a list of Families into another List of Families, matching List Parent [index]

Hello Everyone!

Yet another post on Loading Families using Dynamo. I’ve read through most and they have been helpful but I am stuck on an issue. And I am aware of @erfajo and his dyn addition but I have to stick to the native python route for a couple of reasons including the desire to understand why my code at its current state isn’t functioning as intended.

For a list of Families (“To Load In”):

[0] C:\familyPath1
[1] C:\familyPath2
[2] C:\familyPath3

I want to load them into a list of families of matching Parent [index]:
[0] C:\hostPath1
[1] C:\hostPath2
[0] C:\hostPath3
[1] C:\hostPath4
[2] C:\hostPath5
[0] C:\hostPath6

So C:\familyPath1 should load into C:\hostPath1 & 2, C:\familyPath2 into C:\hostPath3,4,5 and so on…

My code so far:
paths = IN[0] = the hostPaths
lpath = IN[1] = the familyPaths
savpath = IN[2] = the hostPaths with a suffix

So for every [ x ] in familyPaths (to Load in)
open current familyPath
for every [ y ] in hostPath [ x ]
open each child of hostPath [ x ]
load and save

When I just run the for loops without any familydocument calls, my watch list returns the items correctly, showing that it is iterating correctly going from List [0][0]…[0][1]…to [1][0] and so on. I have (2) main issues:

  1. Currently, when all is turned on, it iterates just through the [0] first index of familyPaths (lpath):
    loading in C:\familyPath1 into

My guess is that maybe the lDoc needs to be Closed at some point.

  1. Even with SaveAs options, it only seems to work when I save the families by a different name and cannot save over the same file.

Any help would be greatly appreciated!