Atlanta Dynamo User Group Example...
Embed Size (px)
Transcript of Atlanta Dynamo User Group Example...
Atlanta Dynamo User Group Example (Revit-Dynamo-Excel) This example will take you through the process of pulling Room data out of Revit via Dynamo, pushing
that data into Excel, making changes in Excel, then pulling the changes from Excel back into Revit.
Getting the Room Data out of Revit
To start, open any Revit file that has rooms. This Example will use the Revit File named “Example Rooms
for Dynamo 2015.rvt”. Once it is Open, fire up Dynamo. Set it to “Manual” Run.
The goal here is to pull Room Data from Revit and push it into Excel. So first, place a “Categories” node
that selects “Rooms” and attach it to an “All Elements of Category” node. This will pull all room
elements into Dynamo. If you want to see the 3d Representations of the Rooms, wire in an
“Element.Geometry” node and click “Run”.
Atlanta Dynamo User Group Example 2 | P a g e
Now place a “File Path” node and click Browse. Go to the location where you want to have your Excel
File created. Type in the name of the file you wish to create then click “Open”.
Now place 5 “Element.GetParameterValueByName” nodes along with 5 code blocks for “Name”,
“Number”, “Area”, ”Room Type”, “OccPerSF”. Wire the “All Elements of Category” node into the
element input and wire the Code Blocks into the parameterName input.
Atlanta Dynamo User Group Example 3 | P a g e
Now create a Python Script node and wire the “All Elements of Category” node into the input. Double
click on the node to open up the code editor and input the script below. (the
GetParameterValueByName node does not work for some types of elements/parameters – this is a well
know bug and almost always requires some sort of work-around.)
Connect the Python Output into another “Element.GetParameterValueByName” node along with a Code
Block with the string “Name”.
Atlanta Dynamo User Group Example 4 | P a g e
Now wire all of the “Element.GetParameterValueByName” nodes into a “List.Create” node, then follow
it with a “List.Transpose” node. This will switch the lists from being entire lists of individual parameters
to lists of each parameter of a particular element. Afterwards, create a Code Block with the strings
shown below to act as the headers for the Excel schedule. Add that to the front of the previous list as
shown below. The output from the “List.AddItemToFront” should look similar to below.
Atlanta Dynamo User Group Example 5 | P a g e
Now, create an “Excel.WritetoFile” node. Wire the previously created “File Path” node into the
appropriate input. Likewise wire the “List.AdditemToFront” node into the “data” input of the Excel
node. Into the SheetName input, attach a Code Block that contains the string “Room”. Attach another
Code Block with the integer “0” into the “StartRow” and “StartCol” inputs.
Now Click “Run” and the Excel File of your Data should open up. Be sure to save it before closing
Atlanta Dynamo User Group Example 6 | P a g e
Getting the Room Data back into Revit
Now with the Excel file created, we can “do stuff” inside of Excel, then push that back into Revit. In this
case, we will assign each Room a “RoomType” which will carry along with it an “Occupant per Square
Foot” value which we will then use to calculate a total occupancy.
In the same Excel file as was just created, create another sheet named “TypRooms”. In this enter the
RoomTypes and Occupants Per SqFt for each type. (Forgive me if this is all wrong and completely un-
realistic – I’m an engineer and very ignorant when it comes to what architects would/might need to do
with a Room – just focus on the concept and capability).
Once that is done, copy the correct value into the “Room Type” column of the “Rooms” Sheet.
Atlanta Dynamo User Group Example 7 | P a g e
Assuming the Revit project is still open, fire up Dynamo and start a new workspace. The first task is to
get the Excel data back into Dynamo. Be sure you have saved the Excel file and close it. Now in
Dynamo, create a “File Path” and “File.FromPath” node. Connect that into the file input of an
“Excel.ReadFromFile” node. Now connect that node into the function input of a “List.Map” node. In a
Code Block, create a list of the two sheet names in our Excel File (Rooms and TypRooms). Connect this
inot the list input of the “List.Map”. What this does is it operates the “Excel.ReadFromFile” function
using the file input given on each element of the input list (the Sheet Names). This gives us a list of lists
– the first of which is an array of the data from the “Rooms” sheet, and the second is an array of data
from the “TypRooms” sheet. Click “Run” to pull in the data.
From a Watch Node, you can see that the first index of each list is simply the column headers and thus
needs to be thrown away. First split the list into two separate lists (one for each Excel Sheet) using a
Code Block with x and x, then feed the data from each into a “List.RestOfItems” node.
Atlanta Dynamo User Group Example 8 | P a g e
Note that each index in each data list at this point represents one row of the Excel files. Feeding the
data through a List.Transpose will re-arrange the data into lists that represent each column of Excel data
(Index 0 = RoomNumbers, Index 1 = RoomNames, etc…).
Now that we have the Excel Data back into Dynamo and well-arranged, we need to gather the Room
elements and their data from Revit (similar to part 1). As shown below, the Room Elements, Room
Names, and Room Numbers are gathered.
Atlanta Dynamo User Group Example 9 | P a g e
Now we need to somehow pair up the data from the Revit Rooms back to the data that came from
Excel. To do this we will use the Room Numbers (if using Excel to re-number and re-name the rooms,
then you would need to use some other method to match the two data streams to each other, such as
GUIDs using the “Element.UniqueId” node).
Before we can do this, we must correct a nasty bit of business that Excel has done. Note that the Room
Numbers that are coming from Revit are strings (text), but Excel recognized all of the Room Numbers we
previously gave it as actual numbers, and thus has “reclassified” them as doubles (numbers). There are
a number of ways to correct this, but the Python script below will do what we want – which is to convert
the number 100.000000 to the string 100. Create a Python Script node and write a script as shown
below. Feed the “RoomNumbers” data list from Excel into this Python Script node.
Atlanta Dynamo User Group Example 10 | P a g e
Now that we have two lists of room numbers (which may or may not be matched up), we need to fine
which index of the list from Excel should match up with an index of data coming from Revit. Again,
there are many ways to do this (using key lists and sorting, boolean tests, etc..), but a simple Python
Script is the most efficient way. Create a Python Script feed the Revit Room Number data list into the
IN and the Excel Room Number Data into the IN. (see previous image).
Now feed the resulting list of index numbers into the list input of a List.Map. Into the function input,
feed a “List.GetItemAtIndex” with the Excel Room Type data feeding into the list input (the index input is
left blank as that is the list that the List.Map is operating with).
Atlanta Dynamo User Group Example 11 | P a g e
From the Revit Room Elements, pull the Area values in using an “Element.GetParameterValueByName”
(the same way that we pulled the Room Names and Numbers). Feed this into the “RoomAreas” input on
the code block.
Now we need to get the “Occupants per SF” from the “TypRooms” Excel Sheet using the sorted list of
“RoomTypes”. To do this, we will feed the list of RoomTypes through another copy of the “index of
matches” Python Script and then use those indexes to generate a list of “OccPerSF” values from the
TypRooms Excel data.
Atlanta Dynamo User Group Example 12 | P a g e
Now take the “OccPerSF” matched list and multiply it by the “RoomAreas” to get the occupants per
Below is a solution to take the raw occupants data and ensure that it rounds up to the nearest integer.
Atlanta Dynamo User Group Example 13 | P a g e
Now we need to feed the information we’ve pulled from Excel and calculated in Dynamo back into Revit.
To do this, we will need to start a new transaction. Transactions only accept one input, but we have 3
lists that we need (RoomElements, Room Occupants, and RoomTypes). So we must first combine all of
these lists into one array (a list of lists) using “List.Create” that we can feed through a
“Transaction.Start” node. Once on the other side of the node, we can split the array back into 3
Within the Transaction, use “Element.SetParameterByName” nodes to set the “Room Type” and “Room
Occupant Load” parameters within Revit. Feed the Element outputs into a “List.Create” node and then
feed that into a “Transaction.End” to close out the process.
Atlanta Dynamo User Group Example 14 | P a g e
Go look at a room in Revit and see how the Room Type and Room Occupant Load parameters are now
filled by the data from our Excel/Dynamo processing.
If you have any questions while working through this later, feel
free to email me any questions at [email protected].
Atlanta Dynamo User Group Example 15 | P a g e