> For the complete documentation index, see [llms.txt](https://gitbook.testingwaters.in/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.testingwaters.in/lists/consecutive-points.md).

# Consecutive Points

![](/files/-MGigRmhD_eQS0SYWv28)

{% file src="/files/-MGigbyfvFPMwaqzXVju" %}
Dynamo 2.9
{% endfile %}

```d
def ClosestPointsSequence (stPt, pnts:var[]..[])
{
	return = [Imperative]
	{
		cnt1 = List.Count (pnts);
		pnt1 = pnts;
		pnt2 = [stPt];

		while (List.Count(pnt2)<cnt1)
		{
			pnt3 = List.SetDifference(pnt1,pnt2);
			pnt4 = List.LastItem(pnt2);
			dis1 = pnt4.DistanceTo(pnt3);
			pnt5 = List.SortByKey(pnt3,dis1)["sorted list"];
			pnt1 = List.RestOfItems(pnt5);
			pnt2 = List.AddItemToEnd(List.FirstItem(pnt5),pnt2);
		}

		return pnt2;
	}
};
```

This can be extended to obtain the shortest path connecting a list of points by obtaining sequences with all possible start points and then calculating the length of the connecting poly line

![](/files/-MHCn_OR3YdZN4YvuWrY)

{% file src="/files/-MHCnm7qOMKPs3VWP4ZJ" %}
Dynamo 2.9
{% endfile %}
