Python Script List Issue

Hi everyone,
I am really new to python scripting. I have a small issue with one of the Python Script that I took from this forum.

For single element it works perfectly but when I connect multiple elements or list it shows this error:
“Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 18, in
AttributeError: ‘List[object]’ object has no attribute ‘ConnectorManager’”
I appreciate if you suggest a solution.
Thanks
Here is the Python script:

import clr
import sys
clr.AddReference(“RevitAPI”)
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

elem = UnwrapElement(IN[0])
conIndex =
conValue =

conf = FabricationConfiguration.GetFabricationConfiguration(doc)
connectors = elem.ConnectorManager.Connectors

for c in connectors:
if c.ConnectorType == ConnectorType.End:
connectInfo = c.GetFabricationConnectorInfo()
cn = conf.GetFabricationConnectorName(connectInfo.BodyConnectorId)
conValue.append(cn)
conIndex.append(“C” + str(connectInfo.FabricationIndex + 1))

OUT = conIndex, conValue

@amirjalaliafshar This should help you work with multiple elements:
image

import clr
import sys
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

toList = lambda x : UnwrapElement(x) if hasattr(x, '__iter__') else UnwrapElement([x])

elems = toList(IN[0])
conIndex = []
conValue = []

conf = FabricationConfiguration.GetFabricationConfiguration(doc)

for elem in elems:
	connectors = elem.ConnectorManager.Connectors
	conValue_temp = []
	conIndex_temp = []
	
	for c in connectors:
		if c.ConnectorType == ConnectorType.End:
			connectInfo = c.GetFabricationConnectorInfo()
			cn = conf.GetFabricationConnectorName(connectInfo.BodyConnectorId)
			conValue_temp.append(cn)
			conIndex_temp.append("C" + str(connectInfo.FabricationIndex + 1))
	conIndex.append(conIndex_temp)
	conValue.append(conValue_temp)
	
OUT = conIndex, conValue
2 Likes

Thanks a lot Amol. :ok_hand: :ok_hand:t3: :ok_hand:t3: :ok_hand:t3:

1 Like