Numbering Elements One below Other

Hi!
The task is to assign sequential numbers to windows, starting from the upper. Some Windows are located one below the other. I’m trying with the spline method, but it just numbers the elements in the line plane.

Could you suggest any algorithm etc?
Thanks!! Sorry for the image, I just can upload one.

Hello @RodrigoRoa ,

Welcome to Dynamo Community,
I have solve the similar type of problem, so you can have a reference and update the script as per your requirement.