Okay. I fixed a ton of bugs in the code that connects the TEEs to the adjacent pipes. It ended up being pretty darn complicated. I also was able to group the pipes and fittings into their respective groups to be able to loop this code across multiple TEEs and pipes.

Now I just need to get the ābreak pipesā, āadd teesā and āconnect teesā steps strung together properly but the code should be complete and I should be able to post the .dyn soon.

```
# Load the Python Standard and DesignScript Libraries
import sys
import clr
import itertools
# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('AeccPressurePipesMgd')
# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
# The inputs to this node will be stored as a list in the IN variables.
inputPoints = IN[0]
pipeNetworkDynamo = IN[1]
allPoints = []
for point in inputPoints:
convertedPoint = Point2d(round(point.X, 1), round(point.Y, 1))
allPoints.append(convertedPoint)
adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
cdoc = CivilDocument.GetCivilDocument(db)
try:
pipeNetwork = pipeNetworkDynamo.InternalDBObject
allFittingIds = pipeNetwork.GetFittingIds()
allPipeIds = pipeNetwork.GetPipeIds()
allFittings = []
allPipes = []
allFittingLocations = []
allPipeStartPoints = []
allPipeEndPoints = []
for fittingId in allFittingIds:
fitting = t.GetObject(fittingId, OpenMode.ForWrite)
allFittings.append(fitting)
for fitting in allFittings:
fittingLocation = fitting.Location
allFittingLocations.append(fittingLocation)
for pipeId in allPipeIds:
pipe = t.GetObject(pipeId, OpenMode.ForWrite)
allPipes.append(pipe)
for pipe in allPipes:
pipeStartPoint = pipe.StartPoint
pipeEndPoint = pipe.EndPoint
allPipeStartPoints.append(pipeStartPoint)
allPipeEndPoints.append(pipeEndPoint)
for point in allPoints:
pipes = []
pipeIds = []
for fitting, fittingLocation in zip(allFittings, allFittingLocations):
if abs(fittingLocation.X - point.X) < 2 and abs(fittingLocation.Y - point.Y) < 2:
pFitting = fitting
for pipe, pipeId, startPoint, endPoint in zip(allPipes, allPipeIds, allPipeStartPoints, allPipeEndPoints):
if (abs(startPoint.X - point.X) < 2 and abs(startPoint.Y - point.Y) < 2) or (abs(endPoint.X - point.X) < 2 and abs(endPoint.Y - point.Y) < 2):
pipes.append(pipe)
pipeIds.append(pipeId)
bearings = []
pipePortIndexes = []
p1 = pipes[0]
p1Id = pipeIds[0]
p1StartPoint = p1.StartPoint
p1StartPoint = Point2d(round(p1StartPoint.X, 1), round(p1StartPoint.Y, 1))
p1EndPoint = p1.EndPoint
p1EndPoint = Point2d(round(p1EndPoint.X, 1), round(p1EndPoint.Y, 1))
p1Bearing = p1.Bearing
bearings.append(p1Bearing)
p1Curve = p1.BaseCurve
if abs(p1EndPoint.X - point.X) < 2 and abs(p1EndPoint.Y - point.Y) < 2:
p1PortIndex = 1
else:
p1PortIndex = 0
pipePortIndexes.append(p1PortIndex)
p2 = pipes[1]
p2Id = pipeIds[1]
p2StartPoint = p2.StartPoint
p2StartPoint = Point2d(round(p2StartPoint.X, 1), round(p2StartPoint.Y, 1))
p2EndPoint = p2.EndPoint
p2EndPoint = Point2d(round(p2EndPoint.X, 1), round(p2EndPoint.Y, 1))
p2Bearing = p2.Bearing
bearings.append(p2Bearing)
p2Curve = p2.BaseCurve
if abs(p2EndPoint.X - point.X) < 2 and abs(p2EndPoint.Y - point.Y) < 2:
p2PortIndex = 1
else:
p2PortIndex = 0
pipePortIndexes.append(p2PortIndex)
p3 = pipes[2]
p3Id = pipeIds[2]
p3StartPoint = p3.StartPoint
p3StartPoint = Point2d(round(p3StartPoint.X, 1), round(p3StartPoint.Y, 1))
p3EndPoint = p3.EndPoint
p3EndPoint = Point2d(round(p3EndPoint.X, 1), round(p3EndPoint.Y, 1))
p3Bearing = p3.Bearing
bearings.append(p3Bearing)
p3Curve = p3.BaseCurve
if abs(p3EndPoint.X - point.X) < 2 and abs(p3EndPoint.Y - point.Y) < 2:
p3PortIndex = 1
else:
p3PortIndex = 0
pipePortIndexes.append(p3PortIndex)
deltas = []
bearingCounts = []
#for bearing in bearings:
bearing0differences = [bearings[0] - bearings[1], bearings[0] - bearings[2]]
bearing0count = 0
for bearingDifference in bearing0differences:
if abs(bearingDifference) > 1:
bearing0count = bearing0count + 1
bearingCounts.append(bearing0count)
bearing1differences = [bearings[1] - bearings[0], bearings[1] - bearings[2]]
bearing1count = 0
for bearingDifference in bearing1differences:
if abs(bearingDifference) > 1:
bearing1count = bearing1count + 1
bearingCounts.append(bearing1count)
bearing2differences = [bearings[2] - bearings[0], bearings[2] - bearings[1]]
bearing2count = 0
for bearingDifference in bearing2differences:
if abs(bearingDifference) > 1:
bearing2count = bearing2count + 1
bearingCounts.append(bearing2count)
middlePipeIndex = bearingCounts.index(max(bearingCounts))
bearingsDegrees = [bearing * 57.2958 for bearing in bearings]
#get vectors
pipeVectors = []
#get p1 Vector
if abs(p1EndPoint.X - point.X) < 2 and abs(p1EndPoint.Y - point.Y) < 2: #if p1 endpoint is == point, then should be startpoint of vector
p1VectorStartPoint = p1EndPoint
p1VectorEndPoint = p1StartPoint
else:
p1VectorStartPoint = p1StartPoint
p1VectorEndPoint = p1EndPoint
p1Vector = Vector3d(p1VectorEndPoint.X - p1VectorStartPoint.X, p1VectorEndPoint.Y - p1VectorStartPoint.Y, 0)
pipeVectors.append(p1Vector)
#get p2 Vector
if abs(p2EndPoint.X - point.X) < 2 and abs(p2EndPoint.Y - point.Y) < 2: #if p2 endpoint is == point, then should be startpoint of vector
p2VectorStartPoint = p2EndPoint
p2VectorEndPoint = p2StartPoint
else:
p2VectorStartPoint = p2StartPoint
p2VectorEndPoint = p2EndPoint
p2Vector = Vector3d(p2VectorEndPoint.X - p2VectorStartPoint.X, p2VectorEndPoint.Y - p2VectorStartPoint.Y, 0)
pipeVectors.append(p2Vector)
#get p3 Vector
if abs(p3EndPoint.X - point.X) < 2 and abs(p3EndPoint.Y - point.Y) < 2: #if p3 endpoint is == point, then should be startpoint of vector
p3VectorStartPoint = p3EndPoint
p3VectorEndPoint = p3StartPoint
else:
p3VectorStartPoint = p3StartPoint
p3VectorEndPoint = p3EndPoint
p3Vector = Vector3d(p3VectorEndPoint.X - p3VectorStartPoint.X, p3VectorEndPoint.Y - p3VectorStartPoint.Y, 0)
pipeVectors.append(p3Vector)
normalVector = Vector3d(0, 0, 1)
pipeIndexes = [0, 1, 2]
pipeIndexes.remove(middlePipeIndex)
angle1PipeIndex = pipeIndexes[0]
angle1 = pipeVectors[angle1PipeIndex].GetAngleTo(pipeVectors[middlePipeIndex], normalVector)
angle2PipeIndex = pipeIndexes[1]
angle2 = pipeVectors[angle2PipeIndex].GetAngleTo(pipeVectors[middlePipeIndex], normalVector)
#Connect middle port to middle pipe
pFitting.ConnectToPipe(2, pipeIds[middlePipeIndex], pipePortIndexes[middlePipeIndex])
if angle1 > angle2:
pFitting.ConnectToPipe(0, pipeIds[angle1PipeIndex], pipePortIndexes[angle1PipeIndex])
pFitting.ConnectToPipe(1, pipeIds[angle2PipeIndex], pipePortIndexes[angle2PipeIndex])
else:
pFitting.ConnectToPipe(1, pipeIds[angle1PipeIndex], pipePortIndexes[angle1PipeIndex])
pFitting.ConnectToPipe(0, pipeIds[angle2PipeIndex], pipePortIndexes[angle2PipeIndex])
except:
pass
t.Commit()
pass
# Assign your output to the OUT variable.
OUT = "DONE"
```