Keeping pipes connected after creation

Hi everyone,

I am busy using the “Element.CopyByVector” method to split a length of pipe and place down flanges. It works great, but when the script finishes, the first and last pipe in the run are losing connection to the relevant end connectors like you see below.


I am looking for a way to keep these connected, as the implications of them losing connection means that another system is created.
What I have tried so far is getting the two end connectors of the original pipe, as well as the First connector of the first new pipe, and the last connector of the last pipe and connect those together using the “Connector.ConnectTo” node from MEPover. Unfortunately I have not been successful with this… Can anyone help me? I feel like I am close given that the connections are right next to each other, I just need the right ones I think?
I cannot upload a sample Revit file due to file size, but it is just 4 pipes with the attached Revit Flange family loaded into the routing preference for flanges, with minimum sizes set to allM_Flange - Slip-on - Steel - Class 150.rfa (516 KB) . Any help would be very much appreciated!!
Thank you.
I am using Revit 2019.2 and Dynamo 2.0.3.8811PipeByLengthUnionConnected_DataShapes_testing.dyn (130.1 KB)

I also have this Python code which I found on the forums,

import clr

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

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

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

pipes = UnwrapElement(IN[0])
margin = 0

connectors = {}
connlist =

for pipe in pipes:
try:
conns = pipe.ConnectorManager.Connectors
except:
conns = pipe.MEPModel.ConnectorManager.Connectors
for conn in conns:
if conn.IsConnected:
continue
connectors[conn] = None
connlist.append(conn)

for k in connectors.keys():
mindist = 1000000
closest = None
for conn in connlist:
if conn.Owner.Id.Equals(k.Owner.Id):
continue
dist = k.Origin.DistanceTo(conn.Origin)
if dist < mindist:
mindist = dist
closest = conn
if mindist > margin:
continue
connectors[k] = closest
connlist.remove(closest)
try:
del connectors[closest]
except:
pass

for k, v in connectors.items():
TransactionManager.Instance.EnsureInTransaction(doc)
try:
k.ConnectTo(v)
except:
pass
TransactionManager.Instance.TransactionTaskDone()

OUT = “Done”

As I understand it this is suppose to find the nearest connector and reconnect items. It works for one pipe, but it does not run on the remainder of them, any ideas?


Thank you

Hi Mitchell,

Maybe this will come in handy, just feed it a bunch of elemens that have a connector on them and it will try to find the closest disconnected connector and try to connect to it.ConnectToClosest.dyn (6.5 KB)

3 Likes

Hi T_Pover,

This seems to be working much better than the previous code… Can’t thank you enough!

1 Like

You are the MEP Dynamo God! This little script will save me so much time. Thank you so much! If you have a github or place you share your scripts I would be very interested to see your other work and anything you have for sale!

For those not using groups to model because of the inherit disconnects that result this script will fix that…and quickly. Setup one group copy around, when our read for flow, ungroup run the script on each area and as long as your pipes are the closest connector you will be fine, you got to watch out for fixtures moving if you are type mapping or what not. If your fixture has an open connector closer than your pipe it will connect to itself and do other weird things. Works great for just copying similar areas as well

1 Like

Thanks for the kind words. I have nothing for sale sadly :wink: My site is really old and I haven’t updated it in years, but there are few workflows for Dynamo that I still use every once in a while. https://bimstallatie.sites.google.com/site/bimstallatie/dynamo

You’re welcome. Just three nodes vs the spaghetti monster I had created just to start haha.

I remember seeing at one point you worked with Taco…Do they have you developing their BIM things? I know a few guys here in Canada who work with Taco.

I will check out your site! Thanks again

Funny https://bimstallatie.sites.google.com/site/bimstallatie/dynamo/move-tags-by-scaling-factor

This was next on my list but I have not delved in yet. I wanted to move the tags from on top of each other and other thigns in my model…planned on using bounding boxes if tags even have those. When I get into I will share :wink:

1 Like

Gostaria muito desse código para conectar conduítes a um equipamento elétrico, mas infelizmente não domino Python. Alguém poderia me ajudar?