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.
Hi @SHDW, welcome to the forum!
Please check out How to get help on the Dynamo forums
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
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
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
PipeType Python Code
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
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()