Mark Number incorrect Based on coordinate location

Create a script that assign a mark value to a nested family.

After struggling and research I finally managed to get the correct order of the nested family which starts at Y Greatest / X Lowest (Top Left) then working horizontally then vertically numbering the next item until you reach Y Lowest / X Highest (Bottom Right).

It Should be noted though bottom right isn’t always the most right object. As per this diagram I am able to run the script. it assigns a mark value, but incorrect value (black), I have added the correct number above using text in red

For some reason my script is not linking the ordered number to the actual element mark.

Attached sample file script and script image

Mark Test.dyn (48.7 KB)

Mark Test.rvt (716 KB)

Though I can tag all (tag all not tagged) an added bonus would be that when script is run it auto tags

Future additions:

The numbering must work on an orthographic orientation (Project north) as will add a feature later to input real world coordinates (True North)

https://forum.dynamobim.com/search?q=sort%20by%20y%20then%20x

Mark Test.dyn (37.7 KB)

You need to build tolerance and thought into this and i will highlight that if you use straight X/Y positions that if something is say 100.0001 and another is 100.0000 they may not be in order that you want.

This is why i went down the route of numbering by spline line technique as a better/robust method, sure there are examples of this on the forum.

May be wise not to spend massive time on this since there seems to be a native version coming which is indicated on the Revit Roadmap.

https://portal.productboard.com/y7sfay7zn7yb6rpd43kz2uva/c/413-rule-based-numbering-for-model-elements?&utm_medium=social&utm_source=share

Had a play around with your and it works for the most part. If there is subtle changes it does not update. Added a feature without changing your script that will input easting and northing from True North while numbering is handled from Project North. See Mark and Coord V2

Mark and Coord v2.dyn (61.2 KB)

With bit help from Chat GPT figured out a way to resort the elements based on the sorted list. Though mine works on subtle changes if I aligned squares to underlying CAD drawing the numbering is messed up due to way Revit is programmed in feet and converting to metric, Revit is creating decimal places. See Mark and Coord V1

Added some more Squares and some loose elements. If align the one on far right to the one next to it it tends to renumber these higher, but if move down 1mm it numbers correct. I suppose grand scheme of thing the subtle coordinate change has no bearing on the actual element in construction, but would be nice to somehow have this correct in the drawing without need to subtly move like I have

-EDIT- Issue though I may have several of theses perfectly align along X access and will have to move each one 1mm lower than last which would then affect coordinates

Mark and Coord v1.dyn (79.3 KB)

Mark Test.rvt (748 KB)