Coordinate System Error from MEP Connector Info

I’m having a weird issue with MEP Connector Info+ from MEPover (@T_Pover). The first time I run my graph (from Player or from Dynamo) on a given selected element the node errors. Every selection I run after the initial failed attempt runs perfectly.
image
That line of code is just getting the direction of the connector.
image

Full code here
import clr
import math

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
#The inputs to this node will be stored as a list in the IN variables.
if isinstance(IN[0], list):
	fittings = UnwrapElement(IN[0])
	toggle = 0
else:
	toggle = 1
	fittings = [UnwrapElement(IN[0])]
	
	
def getConnSysType(connector):
	domain = connector.Domain
	if domain == Domain.DomainHvac:
		return connector.DuctSystemType.ToString()
	elif domain == Domain.DomainPiping:
		return connector.PipeSystemType.ToString()
	elif domain == Domain.DomainElectrical:
		return connector.ElectricalSystemType.ToString()
	else:
		return None
	

p = []
dir = []
fd = []
ref = []
conns = []
descript = []
H = []
W = []
R = []
MEP = []
Sys = []
Shap = []
sysClass = []

for fitting in fittings:
	
	
	points = []
	direction = []
	flowdir = []
	refs = []
	connlist = []
	description = []
	height = []
	width = []
	radius = []
	MEPSystem = []
	systemType = []
	shape = []
	systemclass = []
	
	try:
		connectors = fitting.MEPModel.ConnectorManager.Connectors
	except:
		try:
			connectors = fitting.ConnectorManager.Connectors
		except:			
			p.append(None)
			dir.append(None)
			fd.append(None)
			ref.append(None)
			conns.append(None)
			descript.append(None)
			H.append(None)
			W.append(None)
			R.append(None)
			Shap.append(None)
			MEP.append(None)
			Sys.append(None)
			sysClass.append(None)
			continue
	for conn in connectors:
		connlist.append(conn)
		description.append(conn.Description)
		try:
			height.append(conn.Height)
			width.append(conn.Width)
			radius.append(None)
		except:
			try:
				radius.append(conn.Radius)
				height.append(None)
				width.append(None)
			except:
				radius.append(None)
				height.append(None)
				width.append(None)
		shape.append((conn.Shape).ToString())
		
		try:
			MEPSystem.append(conn.MEPSystem.Name)
			systype = doc.GetElement(conn.MEPSystem.GetTypeId())
			systemType.append(systype)			
		except:
			MEPSystem.append(None)
			systemType.append(None)
		
		try:		
			systemclass.append(getConnSysType(conn))
		except:
			systemclass.append(None)
		
		points.append(conn.Origin.ToPoint())
		direction.append(conn.CoordinateSystem.BasisZ.ToVector())
		
		try:
			flowdir.append(conn.Direction.ToString())
		except:
			flowdir.append(None)
		for c in conn.AllRefs:
			refs.append(c.Owner)
	p.append(points)
	dir.append(direction)
	fd.append(flowdir)
	ref.append(refs)
	conns.append(connlist)
	descript.append(description)
	H.append(height)
	W.append(width)
	R.append(radius)
	MEP.append(MEPSystem)
	Sys.append(systemType)
	Shap.append(shape)
	sysClass.append(systemclass)


#Assign your output to the OUT variable.
if toggle:
	OUT = points, flowdir, refs, direction, connlist, description, height, width, radius, MEPSystem, systemType, shape, systemclass
else:
	OUT = p,fd,ref, dir, conns, descript, H, W, R, MEP, Sys, Shap, sysClass

For some background: My graph is essentially replacing one large fitting with two smaller fittings. I delete the original fitting and reconnect the duct (so I have something to connect into with my new fittings). Then I draw new duct and create the two new fittings (Tee.By2MEPCurves). The issue then comes when I try to get the connector info from those new fittings.

I have no idea what would make the coordinate system “inaccessible” on only the first run. Any help would be much appreciated.

EDIT: It does seem like forcing an additional transaction fixes the problem. But why is this only affecting the first object selected? I’ve been using this graph for months now and never had this issue before.

1 Like

I’m living in a scenario that I’m using right now. I thought it was because the script was so severe. So I think the problem is memory. In fact, I have this idea:
It does up to the maximum data that memory can handle, and the rest fails. Then when you run it again, it completes the rest of the script because it’s already done the others.

Possibly. I believe you’re more likely to crash Revit than Dynamo with memory issues. Dynamo also executes everything in one transaction (by default) so it seems unlikely that it could complete with partial data computation and then run again. You’re more likely creating elements that have to be committed before they can be accessed in Dynamo - hence the two runs. That’s the issue I was seeing in my edit, however the transaction is only needed once in my case.

Hi Nick, there is also a separate node for getting the direction. Could you try that node and see if it gives the same error?

Well now everything is working fine today. :expressionless:

This is typical for what we’re working on. We’re basically forcing Revit to do a lot of things that it would rather do automatically and it’s very unstable. As I said, I can force a transaction to ensure that the coordinate system is available for all cases. The bigger issue was that this seemed to draw my fittings but not connect them to any system. That seems to be working again too, so this might be fine for now.

I’ll let you know if it happens again.

1 Like