# Gutter create - Revit API Python

**URL:** <https://forum.dynamobim.com/t/gutter-create-revit-api-python/104867>\
**Category:** Revit\
**Tags:** python, dynamo\
**Created:** [October 3, 2024, 4:07pm UTC](https://forum.dynamobim.com/t/gutter-create-revit-api-python/104867 "2024-10-03T16:07:06Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![cbpires98](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@cbpires98](https://forum.dynamobim.com/u/cbpires98)\
**Post date:** [October 3, 2024, 4:07pm UTC](https://forum.dynamobim.com/t/gutter-create-revit-api-python/104867/1 "2024-10-03T16:07:06Z")

</div>

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?

```auto
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

```

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [October 3, 2024, 4:09pm UTC](https://forum.dynamobim.com/t/gutter-create-revit-api-python/104867/2 "2024-10-03T16:09:40Z")

</div>

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

> **[NewGutter Method](https://www.revitapidocs.com/2023/97920ad4-6479-7004-86f7-651667392d84.htm)**
>
> Online Documentation for Autodesk's Revit API: 2015, 2016, 2017, 2017.1, 2018

---

<div class="post-metadata">

**Author:** ![cbpires98](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@cbpires98](https://forum.dynamobim.com/u/cbpires98)\
**Post date:** [October 3, 2024, 4:34pm UTC](https://forum.dynamobim.com/t/gutter-create-revit-api-python/104867/3 "2024-10-03T16:34:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [October 3, 2024, 7:50pm UTC](https://forum.dynamobim.com/t/gutter-create-revit-api-python/104867/4 "2024-10-03T19:50:59Z")

</div>

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](https://www.revitapidocs.com/2024/7ed9676a-c2bf-7580-41e0-5b1a29e27fb2.htm)

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

---

<div class="post-metadata">

**Author:** ![cbpires98](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@cbpires98](https://forum.dynamobim.com/u/cbpires98)\
**Post date:** [October 4, 2024, 1:14pm UTC](https://forum.dynamobim.com/t/gutter-create-revit-api-python/104867/5 "2024-10-04T13:14:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [October 4, 2024, 2:49pm UTC](https://forum.dynamobim.com/t/gutter-create-revit-api-python/104867/6 "2024-10-04T14:49:31Z")

</div>

Correct, but the Revit geometry curves, not the Dynamo ones. 🙂

---

<div class="post-metadata">

**Author:** ![hoangthanh7897](https://avatars.discourse-cdn.com/v4/letter/h/e79b87/32.png) [@hoangthanh7897](https://forum.dynamobim.com/u/hoangthanh7897)\
**Post date:** [October 9, 2024, 2:17am UTC](https://forum.dynamobim.com/t/gutter-create-revit-api-python/104867/7 "2024-10-09T02:17:57Z")

</div>

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()

---

<div class="post-metadata">

**Author:** ![cbpires98](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@cbpires98](https://forum.dynamobim.com/u/cbpires98)\
**Post date:** [October 10, 2024, 8:31pm UTC](https://forum.dynamobim.com/t/gutter-create-revit-api-python/104867/8 "2024-10-10T20:31:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![cbpires98](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@cbpires98](https://forum.dynamobim.com/u/cbpires98)\
**Post date:** [October 10, 2024, 8:35pm UTC](https://forum.dynamobim.com/t/gutter-create-revit-api-python/104867/9 "2024-10-10T20:35:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hoangthanh7897](https://avatars.discourse-cdn.com/v4/letter/h/e79b87/32.png) [@hoangthanh7897](https://forum.dynamobim.com/u/hoangthanh7897)\
**Post date:** [October 10, 2024, 11:15pm UTC](https://forum.dynamobim.com/t/gutter-create-revit-api-python/104867/10 "2024-10-10T23:15:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cbpires98](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@cbpires98](https://forum.dynamobim.com/u/cbpires98)\
**Post date:** [October 11, 2024, 7:18pm UTC](https://forum.dynamobim.com/t/gutter-create-revit-api-python/104867/11 "2024-10-11T19:18:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![hoangthanh7897](https://avatars.discourse-cdn.com/v4/letter/h/e79b87/32.png) [@hoangthanh7897](https://forum.dynamobim.com/u/hoangthanh7897)\
**Post date:** [October 12, 2024, 1:29am UTC](https://forum.dynamobim.com/t/gutter-create-revit-api-python/104867/12 "2024-10-12T01:29:27Z")

</div>

Sure, here you are.

```auto
#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

```

---

<div class="post-metadata">

**Author:** ![cbpires98](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@cbpires98](https://forum.dynamobim.com/u/cbpires98)\
**Post date:** [October 15, 2024, 8:02pm UTC](https://forum.dynamobim.com/t/gutter-create-revit-api-python/104867/13 "2024-10-15T20:02:25Z")

</div>

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!!

---

<div class="post-metadata">

**Author:** ![cbpires98](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@cbpires98](https://forum.dynamobim.com/u/cbpires98)\
**Post date:** [October 17, 2024, 6:03am UTC](https://forum.dynamobim.com/t/gutter-create-revit-api-python/104867/14 "2024-10-17T06:03:16Z")

</div>

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:

```auto
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]

```

---

<div class="post-metadata">

**Author:** ![cbpires98](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@cbpires98](https://forum.dynamobim.com/u/cbpires98)\
**Post date:** [October 17, 2024, 6:14am UTC](https://forum.dynamobim.com/t/gutter-create-revit-api-python/104867/15 "2024-10-17T06:14:13Z")

</div>

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.
