Automating Trim Extend to Corner



Hi Everyone,

This script maybe reaching a bit here, but its something that could be useful though not really sure if it is possible.

I am essentially trying to automate the Trim Extend to Corner function on the Modify tab in Revit using a python script through Dynamo.

So far I have written this code in two parts. The first was to select elements in the Revit space using Element IDs the second was to basically select the Trim Extend to Corner function. Both of these scripts were successful but putting the two together has not been successful. Although there are no errors, the script does not work.

Below you will find the .dyn file, a snap of the dynamo graph, python node code and a snap of the two duct pieces I am trying to join.

The idea behind this is to naturally run this script on a number of elements that require the Trim Extend to Corner Function.


Trim-Extend Script.dyn (4.6 KB)

Python Block Code:

import clr

import Revit

import RevitServices
from RevitServices.Persistence import DocumentManager
from System.Collections.Generic import *

import Autodesk
from Autodesk.Revit.DB import *

from Autodesk.Revit.UI import *

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIDocument

app = DocumentManager.Instance.CurrentUIApplication.Application
uiapp = DocumentManager.Instance.CurrentUIApplication

#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

elements = [UnwrapElement(i) for i in IN[0]]

pCmd = RevitCommandId.LookupPostableCommandId(PostableCommand.TrimOrExtendToCorner)
TrimExtend = uiapp.PostCommand(pCmd)

for i in elements:
	elementIdList = List[Autodesk.Revit.DB.ElementId]()
	sel = uidoc.Selection.SetElementIds(elementIdList)

OUT = "Complete"
#Assign your output to the OUT variable.


Hi @nikhilmakan02

It’s worth looking at MEPOver package it covers what your looking for:


Hi Kulkul

Thanks for the reply, I had a look through the Python Script for that node unfortunately its not exactly what I was looking for. I apologise as I have misdirected you with the use of two pieces of duct but where I would like to actually use this is with two beams. At the time I didn’t think it mattered what element it was.

The MEPOver node relies on placing a bend between the two pieces of pipe but with two beams there is no bend to be placed in between.