Problem with excluding 3d geometry

I’m trying to make a quite simple column and beam structure.
I’m trying to exclude the extra beams, so the beams that are not supported by a column but i can’t figure it out.

I hope that the script i wrote is useful and thank you for helping in advance!

190801_gridd (16.7 KB)

Something like this?

190801_gridd (29.9 KB)

Exactly like that!!
thank you.

I will study your script for a while! because i’m in awe!