Work with levels in python script input

I bring python code to sort the point accord the distance:

import clr
from Autodesk.DesignScript.Geometry import Geometry

pts = IN[0]
margin = IN[1]
dist1 = Geometry.DistanceTo

Groups, Queue = [ ], [ ]
while pts:
	group = [ ]
	Queue.append(pts.pop() )
	while Queue:
		p1 = Queue.pop()
		for i in xrange(len(pts)-1,-1,-1):
			if dist1(p1, pts[i]) <= margin:
				Queue.append(pts.pop(i) )

OUT = [sublist[::-1] for sublist in Groups[::-1]]

the problem is when the input have more than one list level the code will not give right result as the pic :

how i can work with level lists in python

Hi @Mkq_1993 maybe try

  • add for looping into your python node
  • or use ProcessList def function
  • or create a custom node
  • or flatten list, process list and another python to retrieve the correct level.
1 Like

I can’t deal with python yet, also if i can’t make flatten for list because that will ruin the last sorting

Hi @Mkq_1993 ,

Like paris said, you could put this python script inside a custom node, then list levels and such should work as intended :slight_smile:


Hi @Mkq_1993 can you share a simple RVT file with your dyn?

1 Like

Cable Tray Support3s.dyn (709.3 KB)
i want to move the script after vector direction sorting

Just to add to the topic, if you are willing to put your Python block into a custom node this will enable levels to be used on its inputs. If you list the input to the node in the format…

name: var[]..[]

this will instruct the node to treat the input exactly as is, but enable you to also instruct it to work @L1, L2 etc.

1 Like