This is a type of problem that would have easily been resolved by a network graph that shows all Gramps objects as nodes and all relations between gramps objects as edges and a then used a “show nearest neighbor” with 2 hops algorithm.
It’s not for nothing I kept saying network graphs would be perfect for genealogy research.
Maybe you can use networkx and write a script to use in the Python Gramplet or SuperTool…