My colleague Lee Mullin told you about it already in his latest post when he talked about mapping BIM 360 Field data to COBie data within Revit. To automate this parameter mapping within the Revit environment, Dynamo was used. In this post I am going to explain you how the Dynamo script works and especially, how you can use this script for other purposes which require parameter mapping as well.
Setting up the data
First, you can download the dataset via this link.
- Open the file "Data Mapping.rvt"
- Open Dynamo in the Add-Ins tab within Revit
- Open the file "COBie Translator.dyn"
Before you start using the script you need to configure the parameter mapping in the Excel file. In this case the file is called "COBie Translation.xls".
In that file the left column ("A") is used to set the 'source' parameter names. In the right column ("B") the 'target' parameters are set. As parameter names are case sensitive in Revit, you might want to double check on typos in your Excel table (especially when using Auto-correct).
Once this is set, point to this Excel file in the Dynamo script, by clicking the Browse button on the File Path node.
In this part of the script all the data from the Excel sheet is read, and the first row (with the headers) is removed from the Dynamo data list (array).
Revit object selection in Dynamo
The second step to take in the Dynamo script is to select the objects which need to be included in the parameter mapping. The script delivered in the link above, "COBie Translator.dyn", allows to select different objects, either from categories, either from custom selection in Revit. Let me explain you how the part of this script, captured below, works practically.
Step 1 – Selection criteria
Here you can set your selection criteria. This scripts allows you to select three different categories and with the Select Model Elements node, you can select manually other objects in the Revit model. First you need to press Select, then go to the Revit canvas and select your elements by making a selection window (without starting a selection command in Revit). This won't work by clicking elements one by one !
Step 2 – Detect Null values
It may happen that your model doesn't contain objects of the indicated category or that you didn't need to select manually. In that case, the output will return "null" values.
Step 3 – Replace Null values
The "null" values have to be filtered out, before the script can continue working. The If node will test the output on these "null" values and will replace them with a "DUMMY" string value (which will be cleared out in step 6). If you don't replace this "null" value then you will receive warnings in Dynamo.
Step 4 – Join results
Now all the output results are joined into one list with List.Join. This is an important step to continue with the other operations in step 5 and 6.
Step 5 – Filter unique items
It may happen that your category selected items and the manually selected items return double selected elements. The instance can be selected only once to perform parameter value changing. The List.Uniqueitems will filter the results list on the Revit IDs of the selected objects. The output will be a list with only unique items (double selections are removed from the list, not from the model).
Step 6 – Filter dummy items
In step 3, the "null" values got replaced by a "DUMMY" text string. As theses "DUMMY" strings don't represent a Revit object, they have to be cleared out of the list before we continue. This is executed by the List.Filter node, where we set a condition to filter on "DUMMY" with the = = node. The values in the output port "out" are the ones without the "DUMMY" string.
If you prefer to have more selection methods, then add new nodes for it, as long as you duplicate the nodes in step 2 and 3, wire them accordingly and add the result to a new input port in the List.Join node in step 4.
In this part of the script the parameter names from, coming from the Excel file, are splitted up in two lists. The sublist with index '0' represents the BIM 360 Field parameters. The sublist with index '1' are the COBie parameters that should exist in the Revit model objects.
Once the parameter names are sorted out in Dynamo, we can start by reading the appropriate values from the Revit model and store them in a Dynamo array. The value list needs to be transposed with List.Transpose to make it possible to write the values to the right COBie parameter. Transposing means in this case switching columns and rows within the data array.
The COBie parameters are listed, the values that need be set in these parameters are extracted from the Revit model, then now it is time to write the values to Revit using the Element.SetParameterByName node. Tricky in this part is that you need to set a list of values to a list of elements in a list of parameters. That's why in this case List.Combine is used. This node helps us to combine the parameter with index  with the appropriate value with index ,  with , and so on…
Once all of these is set, you can press "Run" at the bottom left of your Dynamo interface. I advise you to keep the procedure to "Manual" to avoid endless looping of the script, when it changes parameter values all the time.
Well, if you want to see the final result, then check the schedule "Window Schedule" in Revit before and after the run of this script and notice how the COBie values are set.