Have you tried any algorithm, e.g. traveling salesman algorithm? There is a node from Sparrow package, for Revit 2021. See here