NAME ASSEMBLY PARTS BASED ON COORDINATES

Hey does anyone have a macro to organize or name parts and sub-assemblies based on position in the assembly position? There is an example. It honestly doesn't matter where it starts from. I have it so it will go in order but if 2 parts are beside each other by a mate I will get an error. Is this even possible? 

SolidworksApi/macros