Sorry, that solution is not applicable for my current situation.
I need to know how to get blocks with the same X with tolerance factor then reposition them according to the average X value so they will not be moved far than their current positions.
And the same way with Y coordinate.
Hope my explanation is clear enough and I can elaborate the issue if needed.
Thanks.