# Import vertical pipe diameter from excel

**URL:** <https://forum.dynamobim.com/t/import-vertical-pipe-diameter-from-excel/99433>\
**Category:** Revit\
**Tags:** excel\
**Created:** [March 26, 2024, 3:40pm UTC](https://forum.dynamobim.com/t/import-vertical-pipe-diameter-from-excel/99433 "2024-03-26T15:40:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SHDW](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@SHDW](https://forum.dynamobim.com/u/SHDW)\
**Post date:** [March 26, 2024, 3:40pm UTC](https://forum.dynamobim.com/t/import-vertical-pipe-diameter-from-excel/99433/1 "2024-03-26T15:40:45Z")

</div>

Hello,  
I am looking to make a Dynamo script which would use data from an excel file which has inputs (Pipe type, Diameter, level start and end) and construct vertical pipes accordingly with the pipe diameter changes which is given in the excel file. (For example, HWR pipe 50mm from level 1-5 and then changes to 65mm from level 6 to 15). I did make the script for making levels using excel (attached below).  
I am a complete beginner to dynamo and would appreciate the feedback.  
Thank you.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/5/f58b708e9a8d9ac5517936065b0ff4a3ef015a96.png)

---

<div class="post-metadata">

**Author:** ![Mike.Buttery](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Mike.Buttery](https://forum.dynamobim.com/u/Mike.Buttery)\
**Post date:** [April 12, 2024, 9:31am UTC](https://forum.dynamobim.com/t/import-vertical-pipe-diameter-from-excel/99433/2 "2024-04-12T09:31:04Z")

</div>

Hi @SHDW, welcome to the forum! 🤙

Please check out [How to get help on the Dynamo forums](https://forum.dynamobim.com/t/how-to-get-help-on-the-dynamo-forums/4677)

It’s taken awhile to look at your question as it is not a simple request

When looking at a complex problem we can break it down into component tasks, something like this:

- Open excel file and extract data
- Get data and elements from Revit document to assist with task
- Format / manipulate data to be used in Dynamo / Revit
- Process data to create new elements, in this case pipes
- Manipulate new elements in the document, if required

The format of the Excel file is going to be important - here is an example

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/3/c3ea4d655c2d33c4f16a984c432ec0eb9af6dc3c.png)

Here is a work in progress - unfortunately the Orchid node does not appear to be working  
I have had to build python nodes to get pipe types and levels by name

 ![pipes_updated_2024-04-12_05-26-23](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/e/ee27bcc0bb6238ceb6de06535e07db75ac1fe293.png)

---

<div class="post-metadata">

**Author:** ![Mike.Buttery](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Mike.Buttery](https://forum.dynamobim.com/u/Mike.Buttery)\
**Post date:** [April 13, 2024, 12:34am UTC](https://forum.dynamobim.com/t/import-vertical-pipe-diameter-from-excel/99433/3 "2024-04-13T00:34:47Z")

</div>

So how do we get our types when there is no node? For this we will have to use a Python node  
What I am doing here is creating a dictionary - which is like a lookup table with keys and values - we provide the key, the dictionary provides the value. Same for Levels

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/7/b7e8e38ebcadf70578eb40d2a993a649c225cd3b.png)

> **PipeType Python Code**
>
> ```python
> import clr
> 
> clr.AddReference("RevitServices")
> from RevitServices.Persistence import DocumentManager
> 
> clr.AddReference("RevitAPI")
> from Autodesk.Revit.DB import FilteredElementCollector
> from Autodesk.Revit.DB.Plumbing import PipeType
> 
> doc = DocumentManager.Instance.CurrentDBDocument
> 
> pipetypes = FilteredElementCollector(doc).OfClass(PipeType).ToElements()
> pipetypes = {pt.get_Name(): pt for pt in pipetypes}
> 
> OUT = pipetypes.get(IN[0]) if isinstance(IN[0], str) else [pipetypes.get(pt) for pt in IN[0]]
> 
> ```

For me both the MEPover and Orchid nodes are not creating pipes so once again we can create our own node with 5 inputs

> **Python Create Pipe Code**
>
> ```python
> import traceback
> 
> import clr
> 
> clr.AddReference("RevitNodes")
> import Revit
> clr.ImportExtensions(Revit.Elements)
> clr.ImportExtensions(Revit.GeometryConversion)
> 
> clr.AddReference("RevitServices")
> from RevitServices.Persistence import DocumentManager
> from RevitServices.Transactions import TransactionManager
> 
> clr.AddReference("RevitAPI")
> from Autodesk.Revit.DB import BuiltInParameter, ElementId
> from Autodesk.Revit.DB.Plumbing import Pipe
> 
> def element_id(data):
> # Dynamo objects return an integer
> if isinstance(data, list):
> return [ElementId(obj.Id) for obj in data]
> return [ElementId(data.Id)]
> 
> def listify(item):
> if hasattr(item, " __iter__"):
> return item
> return [item]
> 
> doc = DocumentManager.Instance.CurrentDBDocument
> 
> systemtypes = element_id(IN[0])
> pipetypes = element_id(IN[1])
> levels = element_id(IN[2])
> 
> # use Dynamo points as this does automatic unit conversion
> startppoints = [point.ToXyz() for point in listify(IN[3])]
> endpoints = [point.ToXyz() for point in listify(IN[4])]
> 
> TransactionManager.Instance.EnsureInTransaction(doc)
> 
> try:
> pipes = [
> Pipe.Create(doc, st, pt, lev, sp, ep)
> for st, pt, lev, sp, ep in zip(
> systemtypes, pipetypes, levels, startppoints, endpoints
> )
> ]
> 
> OUT = pipes
> 
> except Exception:
> OUT = traceback.format_exc()
> 
> TransactionManager.Instance.TransactionTaskDone()
> 
> ```

 ![pipes_updated_2024-04-13_08-32-57](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/9/093e864f41ef2f0deb81c184359377c1de0cbbdc.png)
