Aligning and connecting fitting with pipe

Hi all,

AlignPartByConnectors method does not properly align the fittings with the pipe connector which makes the connection fail.

t = Transaction(doc, 'Connect p-Trap')
t.Start()

# Pipe Resize
for pipe in pickedPipes:
    pipeSize = pipe.get_Parameter(BuiltInParameter.FABRICATION_PRODUCT_ENTRY).AsValueString()
    pipeLength = pipe.get_Parameter(BuiltInParameter.FABRICATION_PART_LENGTH).AsDouble()
    # Reduce pipe length
    newPipeLength = pipeLength - pipe_size_to_x.get(pipeSize)
    #pipe.get_Parameter(BuiltInParameter.FABRICATION_PART_LENGTH).Set(newPipeLength)
    pipeList.append(pipe)

for pipe in pipeList:
    pipeService = pipe.get_Parameter(BuiltInParameter.FABRICATION_SERVICE_PARAM).AsValueString()
    pipeSize = pipe.get_Parameter(BuiltInParameter.FABRICATION_PRODUCT_ENTRY).AsString()

    # Open connector
    pipeConSet = pipe.ConnectorManager.UnusedConnectors
    pconIterator = pipeConSet.ForwardIterator()
    pconIterator.MoveNext()
    pCon = pconIterator.Current

    ptrapButton = getButton(fabServices, pipeService, 0, 23)
    # Create p-Trap fitting
    fabFitting = FabricationPart.Create(doc, ptrapButton, 0, level.Id)# doc, fitting button, condition, level id
    
    for c in fabFitting.ConnectorManager.Connectors:
        if c.Id ==1:# horizontal connector
            ptrapCon1 = c
        else:
            ptrapCon2 = c# vertical connector

    # just aligns, no joining
    FabricationPart.AlignPartByConnectors(doc, ptrapCon1, pCon, math.radians(0))#doc, fitting con, pipe con, angle
    
    # elbow size = pipe size
    fabFitting.get_Parameter(BuiltInParameter.FABRICATION_PRODUCT_ENTRY).Set(pipeSize)
    
    # Align Again?*
    # Connect with p-Trap
    FabricationPart.ConnectAndCouple(doc, ptrapCon1, pCon)#doc, pTrapCon, pipeCon
t.Commit()

*I also tried aligning the fabFitting again using any one of the below two methods. But it rotates and tosses the fittings around.

    ElementTransformUtils.MoveElement(doc, fabFitting.Id, pCon.Origin)
    FabricationPart.SetPositionByEnd(fabFitting, ptrapCon1, pCon.Origin)

The misplacement is because of:

  • Changing the size of the fitting (from default to pipe size)

@theshysnail ,

check out the PyRevit extensions:
MEPDesign
PyRevitMEP

1 Like