# Enable Python support and load DesignScript library
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.
wallList = IN[0] # Wall Elements
geoList = IN[1] # Wall Geometry (geo)
sortWall = [] # Final sorted list
sortGeo = [] # Final sorted centerpoints
orig = Point.ByCoordinates(0,0,0) # Point used as origin
for _subG,_subW in zip( geoList, wallList ):
_temp = [] # Sorted wall sublist
_geo = [] # Sorted geo sublist
t0 = orig # Base geo for comparison
while len( _subG ) > 0:
t5 = [] # List of distances
for i in _subG:
t5.append( Geometry.DistanceTo( t0, i ) )
t6 = min( t5 )
t7 = t5.index( t6 )
_temp.append( _subW.pop( t7 ) )
t0 = _subG.pop( t7 )
_geo.append( t0 )
sortWall.append( _temp )
sortGeo.append( _geo ) # Add 'sortGeo' to output for sorted geo
OUT = sortWall
vanWallSort.dyn (14.2 KB)
So this uses the point (βorigβ in the script, can change to whatever) as the first comparison. Also if I have time I will clean up the script later and replace the terrible variable names to make it easier to follow. I think using the wall line instead of center point works better but let me know how it works.
Edit: Cleaned up the python a little bit.