Dynamo for Revit Basics – Part 3 of 4: Read to and Write...

7
[email protected] www.imaginit.com 800.356.9050 TECHNICAL WHITEPAPER Dynamo for Revit Basics – Part 3 of 4: Read to and Write from Microsoft Excel Companies that utilize a BIM-enabled workflow always struggle to involve some of their senior staff in the 3d-modelling process. The reason for this struggle is usually due to the neglect of senior management in regards to training. “Project Managers don’t need to know Revit!” or “If you need something done in Revit, just ask the drafter.” If the senior management are set on their ways of using out-dated methods/technology, it can be hard to work within a Revit environment. Well, we cannot pick who we work for, but we can get them involved in Revit without them even having to open the software! They will even get to use something very familiar. Microsoft Excel! This technical paper is going to highlight how a firm can utilize Autodesk® Dynamo for Autodesk® Revit® to create a line of communication between Revit and Excel. After this technical paper, you will be able to write data to Excel from Revit and push data from Excel back to Revit. The Thought Process When creating Dynamo Scripts, it is important to first outline what the final input and output are going to be. Once you have the intended input and outputs prepared, it becomes easier to fill in the gaps. In some cases it is a great idea to have a whiteboard around, so that you can create a rough outline of your script. The Script - Write to Excel Open up a Revit project and start-up the Dynamo add-in. The first step to creating a connection between Revit and Excel is to place the Input and Output. In this case, the output is ‘Excel – Write to File’ and the input is ‘Excel – Read from File.’ Once these nodes are in place, we can start forming the bones that pull it all together. We will start with the ‘Write to File’ node.

Transcript of Dynamo for Revit Basics – Part 3 of 4: Read to and Write...

Page 1: Dynamo for Revit Basics – Part 3 of 4: Read to and Write ...portal.imaginit.com/Portals/0/whitepapers/Dynamo_Revit_Basics_3... · Dynamo for Revit Basics – Part 3 of 4: Read to

[email protected] www.imaginit.com800.356.9050

TECHNICAL WHITEPAPER

Dynamo for Revit Basics – Part 3 of 4: Read to and Write from Microsoft Excel

Companies that utilize a BIM-enabled workflow always struggle to involve some of their senior staff in the 3d-modelling process. The reason for this struggle is usually due to the neglect of senior management in regards to training. “Project Managers don’t need to know Revit!” or “If you need something done in Revit, just ask the drafter.” If the senior management are set on their ways of using out-dated methods/technology, it can be hard to work within a Revit environment. Well, we cannot pick who we work for, but we can get them involved in Revit without them even having to open the software! They will even get to use something very familiar. Microsoft Excel!

This technical paper is going to highlight how a firm can utilize Autodesk® Dynamo for Autodesk® Revit® to create a line of communication between Revit and Excel. After this technical paper, you will be able to write data to Excel from Revit and push data from Excel back to Revit.

The Thought Process

When creating Dynamo Scripts, it is important to first outline what the final input and output are going to be. Once you have the intended input and outputs prepared, it becomes easier to fill in the gaps. In some cases it is a great idea to have a whiteboard around, so that you can create a rough outline of your script.

The Script - Write to Excel

Open up a Revit project and start-up the Dynamo add-in. The first step to creating a connection between Revit and Excel is to place the Input and Output. In this case, the output is ‘Excel – Write to File’ and the input is ‘Excel – Read from File.’

Once these nodes are in place, we can start forming the bones that pull it all together. We will start with the ‘Write to File’ node.

Page 2: Dynamo for Revit Basics – Part 3 of 4: Read to and Write ...portal.imaginit.com/Portals/0/whitepapers/Dynamo_Revit_Basics_3... · Dynamo for Revit Basics – Part 3 of 4: Read to

Dynamo for Revit Basics – Part 3 of 4: Read to and Write from Microsoft Excel 2

[email protected] www.imaginit.com800.356.9050

Take notice of the inputs required for the ‘Excel – Write to File’ node. The inputs have the following requirements:

filePath - Requires the File Path for the Excel File. In order to use this input, the user will have to create a blank Excel file as a placeholder.

sheetName – Requires the name (String) of the Excel sheet. The default is usually “Sheet1”

startRow – The starting row for data in Excel

startCol – The starting column for data in Excel

data – The required data from Revit to fill in the Excel cells

overWrite – A yes/no input that tells Revit whether or not to overwrite existing values.

As an initial step, create an Excel file on your desktop. This excel file will be our primary file for storing the Revit data.

As a start, make sure that your execution bar at the bottom right is set to ‘Manual.’ Once this bar is set to manual, you can begin adding nodes. The first node is the node named ‘File Path.’ Place this node, and connect its output to the filePath input. Click on the “Browse…” button and navigate to the excel file that was recently created.

Add a code block to your screen (double-click on an open space) and add in three variables for the following inputs:

sheetName – “Sheet1”;

startRow – 1;

startCol – 1;

Using code blocks is the fastest way to create variables such as numbers, strings and formulas. Characters within “_” are considered to be text or String.

Page 3: Dynamo for Revit Basics – Part 3 of 4: Read to and Write ...portal.imaginit.com/Portals/0/whitepapers/Dynamo_Revit_Basics_3... · Dynamo for Revit Basics – Part 3 of 4: Read to

Dynamo for Revit Basics – Part 3 of 4: Read to and Write from Microsoft Excel 3

[email protected] www.imaginit.com800.356.9050

As for the data; we will be creating a room schedule. From rooms, the parameters to be used will be Room Names (Name) and Room Numbers (Number). In order to call out these parameters for use in Excel, we need to use the node ‘element.getparameter-valuebyname.’ We will then plug in a node for the parameter name and the placed category type (which are ‘Rooms’). Please Note: ‘Categories’ affects anything having to do with the category itself, ‘All Elements of Category’ affects all placed instances of that category. Place the nodes ‘Categories’ and ‘element.getparametervaluebyname’. After the categories node, place a node labelled ‘All Elements of Category’. Join the three nodes as shown below and add a code block for the parameter “Name”;. This parameter name has to be exactly as it is appears in the Revit Properties Palette. Just like any other programming software, all variables are case sensitive. You should have a node combination similar to the picture below.

Now that we have created this node combination, the same setup could be used for multiple parameters (below). Notice that the All Elements of Category and Code Block are being used multiple times. Nodes can be used more than once for anything that uses the same information.

Page 4: Dynamo for Revit Basics – Part 3 of 4: Read to and Write ...portal.imaginit.com/Portals/0/whitepapers/Dynamo_Revit_Basics_3... · Dynamo for Revit Basics – Part 3 of 4: Read to

Dynamo for Revit Basics – Part 3 of 4: Read to and Write from Microsoft Excel 4

[email protected] www.imaginit.com800.356.9050

For now, we are just going to use “Name” and “Number.” Now that we have the parameters, we have to make a list (list.create) from the two getparameter nodes and we have to Transpose (list.transpose) this list so that the data will print to an excel sheet in the correct format. Transposing will group the data in relevant rows, which means that the first value in “Name” will be in line with the first value in “Number.” Create a bunch of rooms on your 1st floor plan and give the all different room names. Run the Dynamo script and click on the little square at the bottom right of the Transpose node. This will display how the data is being organized.

This data can now be plugged into the ‘Write to Excel’ node. The last variable to be introduced to our Write to Excel node is a Boolean. This Boolean will act as an on/off switch that tells the script whether or not to overwrite the data within the Excel file. If it is set to true, it will overwrite the original data. If it is set to false, it will not update. The completed script should look exactly like this:

Run the script and ensure that your data is being written to Excel accordingly. This same process can be used for doors, windows, walls, etc. If more parameters are required, then just add them to the code block and add more element.getparametervaluebyname nodes.

Page 5: Dynamo for Revit Basics – Part 3 of 4: Read to and Write ...portal.imaginit.com/Portals/0/whitepapers/Dynamo_Revit_Basics_3... · Dynamo for Revit Basics – Part 3 of 4: Read to

Dynamo for Revit Basics – Part 3 of 4: Read to and Write from Microsoft Excel 5

[email protected] www.imaginit.com800.356.9050

The Script – Read from Excel

The good thing about creating the connection for “Read from Excel,” is that most of the nodes that we need are already placed! To start we need to first convert the file.path node into a file before plugging it into the read from Excel node.

Use the sheet name that you used for the ‘Write to Excel’ node as the input for the ‘Read from Excel’ node. Then add a Boolean to ‘readAsStrings’. This Boolean will tell Revit whether or not the data is should be identified as Text. This is most commonly set to “True.” (See example on next page)

Page 6: Dynamo for Revit Basics – Part 3 of 4: Read to and Write ...portal.imaginit.com/Portals/0/whitepapers/Dynamo_Revit_Basics_3... · Dynamo for Revit Basics – Part 3 of 4: Read to

Dynamo for Revit Basics – Part 3 of 4: Read to and Write from Microsoft Excel 6

[email protected] www.imaginit.com800.356.9050

The next step is to push the information gathered from Excel into parameter values. To do that we need to re-Transpose the data from Excel back into their original lists. Add a Transpose node and connect the data output from the Excel.ReadfromFile node to the input of the list.transpose node. Now that we have that data, we need to split the data into two separate lists using code blocks. In the first code block, type “X” to add an input on the front of the code block, followed by “[0]”. This will put the list [0] (Room Names) into its own list. In the second code block, type “X” to add an input on the front of the code block, followed by “[1]”. This will put the list [1] (Room Numbers) into its own list.

Now that we have these separate lists, we can use the node element.set parametervaluebyname to push the data back into Revit. Connect the existing parameter names and category into the inputs and use the code blocks on the left for parameter values.

The final Read from Excel script should look like the following:

Page 7: Dynamo for Revit Basics – Part 3 of 4: Read to and Write ...portal.imaginit.com/Portals/0/whitepapers/Dynamo_Revit_Basics_3... · Dynamo for Revit Basics – Part 3 of 4: Read to

Dynamo for Revit Basics – Part 3 of 4: Read to and Write from Microsoft Excel 7

[email protected] www.imaginit.com800.356.9050

About IMAGINiT TechnologiesIMAGINiT Technologies, a Rand Worldwide Company, is a leading provider of enterprise solutions to the engineering community, including the building, manufacturing, civil and mapping industries. With over 25 years of experience, and over 40 offices throughout North America, we provide the expertise, training and support to help companies realize the full power of design technology, maximize ROI and gain competitive advantage.

IMAGINiT is a leading provider of Autodesk software solutions and the largest North American Autodesk Authorized Training Center (ATC) partner. All of our locations are supported by a vast pool of engineering resources focused on developing real-life business solutions for their local clients.

This script is a great starting point for working with Excel files and Revit. There are thousands of applications for this script and they are not limited to schedules. Data from Excel can be used to manipulate model geometry, building levels, family placement and many other Revit functions. This tool is extremely powerful and will prove to be a positive method for involving non-Revit users in a Revit workflow! Enjoy and keep making your Revit world efficient and fun!

About the Author

Dennis Dixon, Senior Applications Expert