Maintaining list of list through python

i have created python script, for that input is list of connector of a drawpit. drawpit have connectors on all four side and their descriptions are given as North, South, East and West for each side. this python script separates connectors by the side description and sort them base on id.

it is working fine if input is connectors of single drawpit. when input is multiple drawpit connectors. it is not working. please suggest what should i change to my script to work for multiple drawpit.
i also want to maintain list structure.

thanks in Advance.

python script is as below;


import sys
import clr
import math
clr.AddReference(‘RevitNodes’)
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
clr.AddReference(“RevitAPI”)
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB import GeometryObject
from Autodesk.Revit.DB import Surface
from Autodesk.Revit.DB import Connector
clr.AddReference(“RevitServices”)
from RevitServices import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference(“DSCoreNodes”)
from DSCore import *

doc = DocumentManager.Instance.CurrentDBDocument

connectors = UnwrapElement(IN[0])
side = IN[1]
refvec = [0,0,1]
point =
des =
east =
west =
north =
south =
output =

def getConnDesc(connector):
desc = None
try:
desc = connector.Description
except:
pass
return desc

def count(List):
return List.Count

def n(Connector):
return Connector.Id

TransactionManager.Instance.EnsureInTransaction(doc)

for i in connectors:
q = getConnDesc(i)
des.append(q)
a = 0
while a < count(des):

if des[a] == "East":
	east.append(connectors[a])
	a = a+1
else:
	if des[a] == "West":
		west.append(connectors[a])
		a = a+1
	else:
		if des[a] == "North":
			north.append(connectors[a])
			a = a+1
		else:
			south.append(connectors[a])
			a = a+1

if side ==0:
origin = east[0]
sort = sorted(east, key=n)
output.append(sort)
else:
if side ==1:
origin = north[0]
sort = sorted(north, key=n)
output.append(sort)
else:
if side == 2:
origin = south[0]
sort = sorted(south, key=n)
output.append(sort)
else:
origin = west[0]
sort = sorted(west, key=n)
output.append(sort)

TransactionManager.Instance.TransactionTaskDone()

OUT = output

Add another loop before

for i in connector

so as to loop over the sublists.

I wouldn’t touch the python. Add it into a custom node so you can make use of list levels and lacing instead. Th is will also make it easier to maintain your code over time.

1 Like

i will try both suggestions and will inform soon. Thanks alot.

works fine with your suggestion. thanks

1 Like