Cut Pipe/Duct In Half

# -*- coding: utf-8 -*-
__title__   = "Split Pipe/Duct"

#⬇️ IMPORTS
#==================================================
from Autodesk.Revit.DB              import *
from Autodesk.Revit.UI.Selection    import ObjectType, ISelectionFilter
from Autodesk.Revit.DB.Mechanical   import Duct, MechanicalUtils
from Autodesk.Revit.DB.Plumbing     import Pipe, PlumbingUtils

#📦 VARIABLES
#==================================================
uidoc  = __revit__.ActiveUIDocument
doc    = __revit__.ActiveUIDocument.Document #type:Document

#🎯 MAIN
#==================================================
#✨ Limit Selection to Pipe/Ducts
class ISF_Pipe_Duct(ISelectionFilter):
    def AllowElement(self, element):
        if type(element) in [Pipe, Duct]:
            return True

#👉 Select Pipe/Ducts
ref_pipe_ducts = uidoc.Selection.PickObjects(ObjectType.Element, ISF_Pipe_Duct())
pipe_ducts     = [doc.GetElement(ref) for ref in ref_pipe_ducts]

# Iterate through Pipes/Ducts
for elem in pipe_ducts:
    try:
        #📏 Get Middle Point
        crv       = elem.Location.Curve
        pt_start  = crv.GetEndPoint(0)
        pt_end    = crv.GetEndPoint(1)
        pt_middle = (pt_start + pt_end)/2

        # Start Transaction for changes.
        t = Transaction(doc,'Split Pipe/Duct')
        t.Start()   #🔓

        #️✂️️ Cut Pipe/Duct
        if type(elem) == Pipe:
           new_elem_id = PlumbingUtils.BreakCurve(doc, elem.Id, pt_middle)

        elif type(elem) == Duct:
            new_elem_id = MechanicalUtils.BreakCurve(doc, elem.Id, pt_middle)


        if new_elem_id:
            new_elem = doc.GetElement(new_elem_id)
            print(new_elem)

        t.Commit()  #🔒

    except Exception as e:
        print('⚠️Error with ElementId({}): {}'.format(elem.Id,e))

⌨️ Happy Coding!
Erik Frits