Connector sublist

I was retrieving all the duct connectors and i need to collect only the one connector from the connector set. I created a python script. but it is getting an error. Here is my code. anybody can help me to find what is the wrong in the code.

import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPI")
import Autodesk
#from Autodesk.Revit.DB import *
from Autodesk.Revit.DB import Mechanical
from Autodesk.Revit.DB.Mechanical import DuctInsulation
from Autodesk.Revit.DB.Mechanical import DuctShape
from Autodesk.Revit.DB.Mechanical import DuctSettings
from Autodesk.Revit.DB import Connector
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

el = UnwrapElement (IN[0])

cType =
shMlst =
shSlst =

for cn in el:
con = cn.ConnectorManager.Connectors
cType.append(con)

for i in cType:
fi_list = (i[0])
fiLst = fi_list[0]
sha = fiLst.Shape
shSlst.append(sha)

OUT = shSlst

image

You cannot index into Connectorsets (getting a value at the index with the brackets ‘’). So you will have to iterate over every connector in the Connectorset and then get the connector you want.

2 Likes

how can iterate it. is there any method in API?

ConnectorSet (and many other set classes) have a method called .ForwardIterator() which will give you the iterator. From there, iterators have a .MoveNext() method which will go through the set, and a .Current property that will be the current item in the set (in your case, the connector). Here is an example of how to get the connectors from an element:

cons = []
conm = elem.MEPModel.ConnectorManager
iter = conm.Connectors.ForwardIterator()
while iter.MoveNext():
    con = iter.Current
    cons.append(con)
3 Likes

Another option is to use a for loop:

connectors = elem.ConnectorManager
for connector in connectors:
    #do something with you connector here
1 Like

i need to retrieve only one connector from one set not all

Then this for loop should work:

for elem in el:
	conMan = elem.ConnectorManager
	con = [cn for cn in conMan.Connectors]
	cons.append(con[0])
1 Like

Or use a break statement after the first iteration:

first_connectors = []
connectors = element.ConnectorManager.Connectors
for connector in connectors:
	first_connectors.append(connector)
	break
1 Like