import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
import math
pt = IN[0]
newTupla = []
for tupla in range (len(pt)):
newList = []
sortedList = []
x = 0
y = 0
# calcs the medium point
for i in pt:
x += i[0]
y += i[1]
x = x / len(pt)
y = y / len(pt)
med = [x,y]
#calcs the arc tangent for each point
for j in pt[tupla]:
rads = math.atan2(-1*(j[1]-med[1]),j[0]-med[0])
rads %= 2*math.pi
degs = math.degrees(rads)
newPoint = (j[0],j[1],j[2],degs)
newList.append(newPoint)
#sorts the list using the angle
newList = sorted(newList, key = lambda x : x[3])
#removes the angle from the list
for j in newList:
newPoint = (j[0],j[1],j[2])
sortedList.append(newPoint)
OUT = sortedList

Does someone have a solution for that?
Thank you for your time !

I am trying to go through a parametric design exercise to generate building envelope options by translating design constrains on a set of rules in dynamo.

The screenshot bellow shows the envelope of the building represented by their vertex and every nested list of points is the intersection of this lines with the levels defined in Revit.
As next steep I would like to create a Polycurve.ByPoints per level and is here where I need to sort points on each level in a clock wise order.
My goal is to place adaptive components between levels based on 4 reference points

Back to the issue of sorting this set of points with python as you can see in the python code I am trying to calculate the medium point then angle of each point to the medium point and sort the list using the angle.

I can make it work in python in 1 list of points with the same principle you are using in dynamo. My issue is how to do it with multiple nested lists within a list.

Yeah I got that . When the lacing of flatten node is set to longest , you keep your first level of lists. If you take a look at my previous screenshot, or try it yourself, youâ€™all see that .