Gutter create - Revit API Python

Hello, I’m trying to develop a way to automatically implement gutters within Dynamo. However, I realized that there are no blocks that perform this function. So I created a code in Python, but apparently it doesn’t work and I can’t find the error. Can anyone help me?

import clr
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)
gutter_type = UnwrapElement(IN[0])  
curves = UnwrapElement(IN[1])  
gutters = []
for curve in curves:
    try:
        gutter = doc.Create.NewGutter(gutter_type, curve)
        gutters.append(gutter)  
    except Exception as e:
        gutters.append(str(e)) 
TransactionManager.Instance.TransactionTaskDone()
OUT = gutters

There is no API method for NewGutter(gutterType, curve). You need to provide a reference or reference array as per here:

I understood, but I was unsure which entry would be taken as a reference? Is there a specific parameter for the “reference” argument? Sorry if the question is very naive, I’m just starting out in this area of ​​Dynamo

Not at the PC to code something for you, but I can give some directions.

If you think about the way you make a gutter in the UI you have to pick an edge of an existing element. A reference is the selected edge (or another part of an element’s geometry) in API terms. This is obtained first by finding an edge, and then using a method such as this one to create a reference thereto: Reference Property

As far as how to select that edge, that is on you as the add-in developer.

Great, thanks for the explanation! In my code I am selecting the bottom edges of the roofs. The solution in this case is curves. That’s why the input parameters of the code I sent are curves. So in this case I need to reference these curves to apply them to the code as input?

Correct, but the Revit geometry curves, not the Dynamo ones. :slight_smile:

I just took a try to create gutter, you can reference below: you need to pick the edge of bottom roof.
trans = Transaction(doc, “Create Gutter”)
gutter = UnwrapElement(IN[0])
gutter_type = doc.GetElement(data.GetTypeId())
trans.Start()

pick_edge = uidoc.Selection.PickObject(ObjectType.Edge)

new_gutte = doc.Create.NewGutter(gutterType, pick_edge)

trans.Commit()

Great, I’ll try that! In this case, you only entered the gutters for the code? How did you insert the lower edges of the roofs?

I was trying other ways to install the gutters, because I was having trouble using codes, but none of them had any effect. So I’m going to try again to work with this alternative following the tips you mentioned.

pick_edge = uidoc.Selection.PickObject(ObjectType.Edge), this method will enable you to select edge reference of the roof.

Hello! I tried to insert this form of code into mine, and apparently it didn’t work. Could you show me what your code looks like?

Sure, here you are.

#Template
import clr
import sys
import System
from System import Array
from System.Collections.Generic import *


clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *

# Import RevitAPI
clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI.Selection import *
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

trans = Transaction(doc, "Create Gutter")
gutter = UnwrapElement(IN[0])
gutter_type = doc.GetElement(gutter.GetTypeId())
trans.Start()

pick_edge = uidoc.Selection.PickObject(ObjectType.Edge)

new_gutte = doc.Create.NewGutter(gutter_type, pick_edge)

trans.Commit()

OUT = new_gutte

It’s great, it really worked! Thank you very much! Is its output normal to show “null”? Furthermore, I will try to change it in some way to insert a set of edges already selected for the code! Because, within the routine I’m creating, I want the gutters to automatically insert themselves into these edges. But this code helped me a lot, I believe I was making a mistake when importing the libraries. Thank you very much again!!

Guys, I tried to create a new code to work with a list of edges instead of selecting them according to hoangthanh7897’s code. I’m based on code from another topic here on the forum, but I believe I’m running into the same edge reference problem, as Dynamo warns that the set of lines are not ModelCurves. Does anyone know what I can do?

This is the code:

import clr

#Import the Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

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

#Import ToDSType(bool) extensions method
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

#Reference the active Document and application
doc = DocumentManager.Instance.CurrentDBDocument

#Start scripting here:

gt = UnwrapElement(IN[0])

lines = UnwrapElement(IN[1])

ref = ReferenceArray()

for i in range(len(lines)):
    ref.Append(lines[i].GeometryCurve.Reference)

TransactionManager.Instance.EnsureInTransaction(doc)

gutter = [doc.Create.NewGutter(gt, ref).ToDSType(False)]

TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.
OUT = [gutter,ref]

And I managed to correct the previous issue about the null output, it was a transaction error in dynamo due to other open codes! Thank you very much, you gave me incredible help in understanding what I needed to do. I’m still trying to create the gutters with an edge list, but thanks again anyway. Without this forum I would be completely lost.