Turn pipe segments into single pipe

Hi all,

Does any one have any suggestions about how to take the situation in the image below (Multiple pipe segments) and turn them into one single pipe? Preferably by reconnecting each one to its adjacent pipe?

Any help or advice would be greatly appreciated!

1 Like

Hello
an example with Python and Revit API, at the input you need to make a list of lists of pipes group (same alignment) or one List of Pipe with same alignment

import sys
import clr

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

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

import System
from System.Collections.Generic import List

doc = DocumentManager.Instance.CurrentDBDocument

def getConnectTo(connector):
    elemOwner = connector.Owner
    for refCon in connector.AllRefs:
        if  refCon.Owner.Id != elemOwner.Id and     refCon.ConnectorType == ConnectorType.End:
            return refCon
    return None     

def getConnecDistant(group):
    lstCon = []
    for elem in group:
        if isinstance(elem, MEPCurve):
            connects = elem.ConnectorManager.Connectors
        else:
            connects = elem.MEPModel.ConnectorManager.Connectors        
        lstCon.extend(connects)
    pairLst = [[x, y] for x in lstCon for y in lstCon ]
    pairLst.sort(key = lambda x : x[0].Origin.DistanceTo(x[1].Origin))
    return  pairLst[-1]

toGroup = lambda x : x if hasattr(x[0] , '__iter__') else [x]
lstGoupPipe = toGroup(UnwrapElement(IN[0]))

TransactionManager.Instance.EnsureInTransaction(doc)
for group in lstGoupPipe:
    con2DistanA, con2DistanB = getConnecDistant(group)
    pipeA = con2DistanA.Owner 
    #prepare list to delete
    lstgroupId = List[ElementId]([x.Id for x in group if x.Id != pipeA.Id])
    #get connector to move
    seconConPipeA = [ x for x in pipeA.ConnectorManager.Connectors if x.Id !=  con2DistanA.Id][0]
    conToConnect = getConnectTo(con2DistanB)
    if conToConnect:
        seconConPipeA.ConnectTo(conToConnect)
        seconConPipeA.Origin = conToConnect.Origin
    else:
        seconConPipeA.Origin = con2DistanB.Origin   
    doc.Delete(lstgroupId)          
TransactionManager.Instance.TransactionTaskDone()
3 Likes

Wow, thank you C.poupin, works perfectly!

Really wish I knew Python like this…
Thanks again for your help, I really appreciate this!