Sort Grid Points by Proximity to Edges of Grid

Hi all-

I am trying to sort a grid of points such that the outermost layer of points gets sorted 1…n*4 where n is the # of rows and cols in the grid. Then the next layer in, then the next, and so on.

When I take a Grid SOP and plug it into the Sort SOP, I am given many options but none seem to fit what I’m trying to do. The closest I can come is choosing Proximity to a Point (0,0,0), but this sorts in radial pattern, not the Square pattern I am looking for.

Is there a way to do an expression-based Sort? In this case I would like to sort by: Max(abs(tx),abs(ty)). I believe this would give me the result I’m looking for but i can’t find a way to make it work…Please help! (Touch file attached).
gridSortProblem.toe (7.78 KB)

check out the Script SOP - this will let you mangle all your points and vertexes in Python.

See Help->Operator Snippets to see some examples using the Script SOP to help you on your way.