Work with levels in python script input

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

import clr
clr.AddReference('ProtoGeometry')
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()
		group.append(p1)
		for i in xrange(len(pts)-1,-1,-1):
			if dist1(p1, pts[i]) <= margin:
				Queue.append(pts.pop(i) )
	Groups.append(group)

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
thanks

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.
    Cheers
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

1 Like

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:

3 Likes

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

1 Like

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

https://easyupload.io/yru782

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