When I first started my blog, my original intent was to cover equal parts Dynamo content and Revit API content. Due to numerous circumstances, I dove headfirst into developing plug-ins for Revit and haven’t spent much time in Dynamo since August of last year. Every time I did go in to write a script, I also encountered some of the same frustrations. Don’t get me wrong, I think Dynamo is invaluable, but if you don’t utilize the Revit API, there are limitations. Recently, I’ve been spending more time in Dynamo and am going to start interjecting some Dynamo posts on my blog. Of course anything you can do in Dynamo you can due purely in Python or C#, but I see value in creating graphs including ease of use and speed. I think there is a benefit to using Dynamo nodes but also to utilizing opportunities to make your graphs more efficient. Currently, I’m trying to collect Python snippets that you can use in a Python node in Dynamo to make your workflow faster and easier.
A minor note on terminology, when I am discussing parameters for elements in Revit I will do my best to always refer to them as Revit parameters to avoid confusion with method parameters.
Personally, one of my least favorite things to do in Dynamo is filter lists. I find filtering with nodes unnecessarily complicated and often I need so many nodes to filter out what I want. One of these examples is filtering for Revit parameters. Last week, for example, I wanted a Dynamo script to turn off the visibility setting of a certain instance Revit parameter in all the title blocks in a project. I wrote two helpful nodes that are super simple but save you so much time.
The first challenge I ran into is we had planning packages and construction document sheets set up and not all of them contained the Revit visibility parameter I wanted to toggle. So the first Python node finds all elements that have a certain Revit parameter.
The node has two inputs. The input at index 0 is a list of elements and the input at index 1 is a list of the element’s Revit parameters. You can get these inputs with Dynamo nodes (see graph at the end of this post). After creating a new empty list, the node then looks at each element and that element’s Revit parameters. If the element has a Revit parameter with the name “Consultant Stamp” it adds it to our new list. You can copy and paste the code below into a Python node in your own Dynamo script and change the p.Name from “Consultant Stamp” to the Revit parameter relevant to you. Please note when comparing strings, the name needs to be an exact match including spaces and capitalizations. The block then returns a list of elements that have a Revit parameter equal to the p.Name you specified.
After I found all the title blocks that had the Consultant Stamp Revit parameter, I wanted to hide it if it was visible so I had to filter the list one more time. This time, I needed to filter by the Revit parameter value. This node will only have one input and that will be the list of Revit parameters of the elements we filtered with the previous Python node.
Because the Consultant Stamp Revit parameter is a visibility Revit parameter, a value of 0 means it is hidden and a value of 1 means it is visible. I want to check if p.Name is equal to “Consultant Stamp” and p.Value is equal to 1. In other words, I want to select all the elements with the Revit parameter “Consultant Stamp” equal to 1 which means it is visible. Then we can add the element to our new list. The output will be a list of the Revit parameters that we need to hide. We can do this using the Revit Parameter.SetValue node and simply set the value to 0. Remember to also update the p.Name in this node.
And this is what the graph looks like in use:
And now when we connect our Python nodes with the other nodes, we can easily change the value of a Revit parameter. These nodes can be reused to filter for a number of Revit parameters for different types of elements, not just title blocks. I hope this gives you a few tools that you can use and modify to make your Dynamo workflow more efficient. Happy scripting!