How to make the intersecting wall the host?

Hello Guys,
i got the following problem in my script:

As you can see in the first picture, all bounding boxes that are to be loaded are packed into the first wall from the list of walls. However, I want the host of the family to be the wall that also intersects with the mep element. So I’m not sure what the best way is to find the right host for each mep element. Does anyone have an idea how to solve this? Many thanks in advance.

Are the walls in a linked file or the host model?

Host model