Good morning, I had this routine but it wasn’t me who developed it, and in an attempt to use it in revit 2025 it is reporting this error, could anyone help me?
There are some issues with the code:
Overwriting buitlin types and imported classes dir and MEPSystem with empty lists will cause errors.
Rather than trying / excepting are there checks in the API?
Here’s how to get connectors with a function
def get_connectors(element):
# Requires an element with connectors
if isinstance(element, FamilyInstance) and element.MEPModel:
return element.MEPModel.ConnectorManager.Connectors
if isinstance(element, MEPCurve):
return element.ConnectorManager.Connectors
I’ve taken the liberty to refactor your code
Refactored code
import clr
from System import Enum
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Mechanical import DuctSystemType
from Autodesk.Revit.DB.Plumbing import PipeSystemType
from Autodesk.Revit.DB.Electrical import ElectricalSystemType
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
def getConnSysType(connector):
domain = connector.Domain
if domain == Domain.DomainHvac:
return Enum.GetName(DuctSystemType, connector.DuctSystemType)
if domain == Domain.DomainPiping:
return Enum.GetName(PipeSystemType, connector.PipeSystemType)
if domain == Domain.DomainElectrical:
return Enum.GetName(ElectricalSystemType, connector.ElectricalSystemType)
def get_connectors(element):
# Requires an element with connectors
if isinstance(element, FamilyInstance) and element.MEPModel:
return element.MEPModel.ConnectorManager.Connectors
if isinstance(element, MEPCurve):
return element.ConnectorManager.Connectors
# Element is not a fitting or MEP element
return str(type(element))
doc = DocumentManager.Instance.CurrentDBDocument
fittings = UnwrapElement(IN[0]) if isinstance(IN[0], list) else [UnwrapElement(IN[0])]
results = []
for fitting in fittings:
connectors = get_connectors(fitting)
if not connectors:
# Element does not have connectors
results.append([[fitting.Id, connectors]] + [None] * 13)
continue
for conn in connectors:
item_results = []
item_results.append(conn.Owner.Id)
item_results.append(conn)
item_results.append(conn.Description)
item_results.append(Enum.GetName(ConnectorProfileType, conn.Shape))
if conn.Shape == ConnectorProfileType.Round:
item_results.extend([None] * 2)
item_results.append(conn.Radius)
elif conn.Shape in [
ConnectorProfileType.Rectangular,
ConnectorProfileType.Oval,
]:
item_results.append(conn.Height)
item_results.append(conn.Width)
item_results.append(None)
else:
item_results.extend([None] * 3)
if conn.MEPSystem:
item_results.append(conn.MEPSystem.Name)
mepsystype = doc.GetElement(conn.MEPSystem.GetTypeId())
item_results.append(mepsystype)
else:
item_results.extend([None] * 2)
item_results.append(getConnSysType(conn))
item_results.append(conn.Origin.ToPoint())
item_results.append(conn.CoordinateSystem.BasisZ.ToVector())
item_results.append(Enum.GetName(FlowDirectionType, conn.Direction))
item_results.append(list(conn.AllRefs))
results.append(item_results)
# Check for single result
if len(results) == 1:
OUT = results[0]
else:
# This will return a list of information collected by connector
OUT = results
# This will return a list of information collected by values
# Order of values:
# fitting, connector, description, shape, height, width, radius, mepsystem, mepsystemtype, systemclass, origin, direction, flowdir, refs
OUT = zip(*results)
I reviewed the code at the top of this thread.
I did have a look at the dyn, however I could not untangle the logic to be able to provide a review.
You can use the code in the drop down
I mean, the python script node isn’t showing an error. Nor can we see that’s happening as the previews below the node are not visible. Its not easy to tell whats happening here when you dont show the output nor the error messages