Numbering beams with same x and y coordinates in a frame

Hello, I am new in Dynamo.
I am trying to build a script to renumber the beam elements in my structure. My script works numbering the beams along x axis (from left to right) and along y axis (from bottom to top).
What I would like to do now is to have the same name for the beams placed on the same x&y coordinate. I mean…a beam placed in floor 4 with coordinate x=0 y=6 z=4 with name B4-1should have the same name of the beams in floor 3 or 5 with the same x and y coordinates but different z. (they will be B3-1 and B5-1. As you can see all of them are numbered with 1).
How can i do it?
Thanks a lot in advance!

Are all floor layouts the exact same? Would you ever have matching elements that aren’t in the same order? Do the beam numbers have to be consecutive?

You should be able to just group your beams by x-coordinate and then y-coordinate. The tricky part is dealing with the issues I mentioned above.

Hi @Nick_Boyts thanks for your reply, unfortunately the floor layouts are not the same. What is tricky to me is that for example I could have a beam in floor 4 numbered as 4-1 but there could not be any beams in that x&y coordinates at floor 3. And what I would like to have is that at floor 3 that position will be not used so the counting starts from the beam 3-2.

Yeah the beams should be consecutive following a x (from left to right) and y (from bottom to top) rule…

Ok this is what I was wondering about. So numbering will not necessarily be continuous if a location is missing. I think that actually makes things easier. I think you just need to sort/group your points by x and y. Each subgroup (with matching coordinates) then gets number sequentially. If a floor does not have that location it will not be in the sublist and will therefor get skipped.

Try searching for posts that sort or group items by 2 values. There are many on points specifically.