Sort by X Y location

I’m trying to write a routine that places consecutive numbers in a parameter where the order is based on X Y location.

For example number rooms on a level with lowest number at bottom left with increasing values up towards top right.

Archi-lab have a blog post where there is some python script to do just that (http://archi-lab.net/room-numbering-with-dynamo/) but it is based on old Dynamo version and seems to rely on a tool kit. Needless to say it doesn’t work.

But I’m sure it doesn’t have to be that complicated. I’m actually acting on Generic Model families. If I could get the insert point XY values for each I could sort them. I found a node to get a Bounding Box from which I presume I could extract an X Y value to use.

Is this the best approach?

I guess you could just use the solid centroid (assuming the generic model families had just one solid each)

The XY sorting is an interesting mathematical question.

  • Does X=3, Y=4 come before or after X=4, y=3 ??
Perhaps you could calculate the distance from the origin or a suitable point- that would be close enough

I’ve used the corner of bounding box for my XY coordinate.

But I can’t find a node to calculate the distance between 2 points. I can create a vector using Vector.By TwoPoints, but not a length.

 

 

Answered my own question - use Vector.Length node.

Would be nice to be able to pick a base point though - I couldn’t find a node where a user can select a point.

This node sorts by distance from element at bottom left (i.e. minimum XY coordinate values).

 

 

This one sorts by combining XY values, which seems to have pretty similar results.

Geometry.DistanceTo is one step less

 

 

can view the first picture, can you re-upload please.