Revit/Dynamo/Python Tutorial – Auto join concrete elements

As many of you will appreciate, the joining of in-situ concrete elements is critical when modelling structures. This ensures that the volume of concrete is correct and makes the construction drawings legible. It is worth understanding how Revit reacts in a default situation when working with in-situ concrete members.

When working with in-situ concrete elements, Revit will automatically join the following elements as shown in the table below. This can be very useful and greatly increases efficiency when modelling.

The order in which elements join is also predetermined by the software. You will find that walls and floors are the primary elements, and these will take priority when joined to other structural elements.

The auto joining property is useful in some situations but can cause issues. For example, you may want the columns to take priority and have floors ‘cut’ around the column’s perimeter. Another situation may be that walls should be continuous and not broken by floors. In these situations, you can use switch join order.

Automating Joins with Dynamo

In the last few releases of Revit, Dynamo has some additional nodes which can help us when working with in-situ concrete. The nodes shown below are all found within Revit – Elements – Element menu.

As you can see, these are simple to use and just requires a selection list of the two element sets. Of course, the selection can be made automatically by collecting all elements of a certain category with a specific material type. In the example below, all structural foundations are selected, the structural material instance parameter is collected and filtered if it contains the string ‘In-Situ’.

However, there is no provision in Dynamo to switch the join order of elements. This is where we can use the power of the Revit API and Python to plug this gap.

The first step is to perform a search on revitapidocs.com. Everything you can automate within Revit is listed on this webpage if it’s not here you cannot achieve the automation! You can then search for the method ‘switch join order’, the method is the code that performs this operation.

Before the Python node can interact with Revit you will need to copy and paste some boilerplate code. This can be located here:

https://dynamopythonprimer.gitbook.io/dynamo-python-primer/getting-started/boilerplate-setup-code

These lines of code setup the various resources you will need to interact with Revit.

The below image shows the Python node. The lines of code shown with the blue border is the specific code that executes the switch join order method.

If the operation is changing elements within Revit, then you must perform a transaction. This is the first and last line within the blue box. The next two lines of code are getting lists of elements at IN[0] and IN[1]. Notice that the list is also unwrapped. Basically, this makes the actual Revit elements useable within Python.

The code then iterates through the nested list and finally executes the switch join order operation for each item in the list. You will notice that this line of code is from RevitAPIDocs.

Notice that as you start typing ‘Autodesk.Revit.DB.JoinGeometryUtils’, the relevant classes and methods are listed.

If you would like to see a step-by-step example of this, then feel free to watch my YouTube Tutorial. Be aware that you will need 25mins to watch this tutorial.

Advertisement

Revit – Stripping Views and Sheets from the model prior to upload to CDE

Many Consultants will have the requirement to strip out all the views, schedules, CAD links and sheets from a model prior to issuing; this is done for a number of reasons such as file size reduction and also protection. If the model is simply for coordination then there is no need to see any of these elements.

Revit - Dynamo Player to Strip Views from Project

You can of course remove all the elements manually from the project but this is very time consuming. You can also purchase apps that will automate these operations but for the few times a month that you need this it is better to use this Dynamo script!

Below you can see a quick video of the Dynamo Script working with Dynamo Player (Revit 2018.1). I also show and explain each element of the script.

Here is the script that you can recreate for your own use. Unfortunalty I cannot directly host the Dynamo script on my blog site.

Strip Views from Revit - Dynamo Graph

Hope this helps,

Lawrence

Revit 2017.1 & Dynamo Tutorial – Setting All Rebar Visible and Solid in View

As many of you will already know, controlling the visibility of reinforcement within Revit can be challenging and time consuming as each new rebar modelled needs to have the visibility set, for example, you create a new range of rebar and then are required to click ‘View Visibility States’ and then select the views that you wish to see the rebar unobscured and ‘as solid’.

Link to Video: https://youtu.be/BmDQ02GhtfE

revit-rebar-view-visibility

In this tutorial I will take you through the steps required to write your own app to automatically control the rebar visibility, the tutorial will use Dynamo 1.2.1 and Revit 2017. With this tutorial no external packages are required.

Here is the end result of the tutorial shown in the video clip below.

dynamo-player

  1. Open an existing model that contains a 3D view with Reinforcement and leave the 3D view active.
  2. On the Manage ribbon, click the Dynamo Icon and start a new dynamo session.
  3. Create the following nodes as shown below (Leave the Python Script Node to step 4).

revit-rebar-visibility-dynamo

I have labelled each node so you can understand how each node operates but feel free to watch the short tutorial video if you have never used Dynamo before.

4. In the Search Bar in the Node library search for Python and add the Python Script node as shown below.

python-script-node

Double Click the Python Node in the grey area as shown below to open the ‘Edit Python Script’ dialog box.

python-edit-script-node

Copy and Paste the Python Script below and Accept Changes (to Line 35).


import clr
#Import RevitAPI for Rebar Control
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference("System")
from System.Collections.Generic import List

# Import RevitNodes
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

#Assign Inputs and Output
rebarElements = UnwrapElement(IN[0])
views = UnwrapElement(IN[1])

#Change rebar Visibility
TransactionManager.Instance.EnsureInTransaction(doc)
for view in views:
 for rebarElement in rebarElements:
 rebarElement.SetUnobscuredInView(view,1)
 rebarElement.SetSolidInView(view,1)
TransactionManager.Instance.TransactionTaskDone()

OUT = rebarElements

Your Code should now look like the image below.

python-code
Add an additional input to the Python node as shown below and wire the Rebar elements into IN[0] and the view into IN[1]. (Note that even if you are just requiring one view it must be a list for the Python Code to run without errors.)

python-script-node-with-second-input-added

Dynamo Player (Revit 2017.1)

For those of you running Revit 2017.1 you can run this simple tool directly from the Player without having to open Dynamo, this could be very useful for people that want to use these tools without wanting to open Dynamo.

On the Manage Ribbon, select the Dynamo Player Icon as shown below.

dynamo-player-icon

The Dynamo Player will then launch, you need to select the folder icon as shown in the image below and browse to the folder that contains your .dyn files. You can then simply play the script!

dynamo-player-folder

Revit and Dynamo  – Set Rebar Unobscured and solid