I’m working on a script to automate parameter updates for elements connected to Duct Accessories. Specifically, I want to identify any Ducts or Duct Fittings physically connected to an accessory and push a value to a specific parameter on those neighbors.
I am using the MEPover package, but I’m hitting a wall at the connector stage.Element.Connectors consistently returns null or empty lists, even when the accessories are properly snapped into the duct line in Revit.
The python in the MEPover custom nodes is getting a little on the crusty side
Here is some refactored updates that should work with any flavour of python
Connected Connector
import clr
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import ConnectorType
# Many thanks to Konrad K Sobon for his awesome ProcessList function!
def ProcessList(_func, _list):
return list(
map(lambda x: ProcessList(_func, x) if type(x) == list else _func(x), _list)
)
def getAllRefs(connector):
refs = []
try:
if connector.IsConnected:
refs = [
x
for x in connector.AllRefs
if x.Owner.Id != connector.Owner.Id
and x.ConnectorType != ConnectorType.Logical
]
except Exception:
pass
if not refs:
return None
return refs if len(refs) > 1 else refs[0]
if isinstance(IN[0], list):
connectors = ProcessList(UnwrapElement, IN[0])
else:
connectors = [UnwrapElement(IN[0])]
# Assign your output to the OUT variable.
OUT = ProcessList(getAllRefs, connectors)
Connector Host
import clr
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
# Many thanks to Konrad K Sobon for his awesome ProcessList function!
def ProcessList(_func, _list):
return list(
map(lambda x: ProcessList(_func, x) if isinstance(x, list) else _func(x), _list)
)
def getConnHost(connector):
host = None
try:
host = doc.GetElement(connector.Owner.Id)
return host
except Exception:
pass
if isinstance(IN[0], list):
connectors = ProcessList(UnwrapElement, IN[0])
else:
connectors = [UnwrapElement(IN[0])]
# Assign your output to the OUT variable.
OUT = ProcessList(getConnHost, connectors)
It’s not that you need nodes from the package - it’s that the MEPover package requires IronPython 2.7 to actually run, unless you factor the code like @Mike.Buttery has recommended.