Renumber Room by Distance to the next Room

So I don’t know how your data is structured and be warned that I am using a while loop so make sure you save everything first but I got a python script to go through a list of rooms sorting using what I think is the right logic:

# 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.
t0 = IN[0] #Starting room
t1 = IN[1][0] #Starting room's geometry
t2 = IN[2] #Rest of the rooms
t3 = IN[3] #Rest of the rooms' geometries
t4 = [t0]

while len(t2) >0:
	t6 = []
	for i in t3:
		t6.append(Geometry.DistanceTo(t1, i))
	t7 = min(t6)
	t8 = t6.index(t7)
	t4.append(t2[t8])
	t2.pop(t8)
	t1 = t3.pop(t8)

# Place your code below this line

# Assign your output to the OUT variable.
OUT = t4

It will start with the room you choose, and cycle through all of the rooms, finding the smallest distance. Then it will use this new room and cycle through to the smallest distance to it and on until it finishes all of the rooms. The output is the ordered list of rooms.

See this graph for how it is laid out. Note that I did make the geometry outside of the python script because it was easier but it may slow down the processing time.

2 Likes