Introduction
In today's article, I will share with you an idea about a connectivity tool that opens up countless opportunities related to data analysis, AI, Machine Learning, and much more. That is how to connect Revit with Jupyter Notebook.
Before we dive in, I'd like to share some basic information about Jupyter Notebook and why it's important for the construction industry.
Jupyter Notebook - Revit API
Jupyter Notebook is an open-source tool, application, programming environment that allows you to create and share interactive documents containing code, equations, images, and descriptive text. What's special is that you can write code, execute it, and view the results right at the moment you write the code. This helps you save time and increase work efficiency. Additionally, you can directly write documentation within Jupyter Notebook, enabling you to create descriptions, guides, and reports easily and quickly.
Revit is a software for designing and managing construction projects, developed by Autodesk. Revit provides a range of powerful tools to help you design, analyze, and manage construction projects efficiently. What's particularly notable is that Revit provides a powerful API, allowing you to interact with data, designs, and manage construction projects flexibly and effectively. However, interacting with Revit's API is not always easy, especially when exchanging and analyzing data with other tools like Python, R, Matlab, and many more.
Connecting Revit with Jupyter Notebook
If you're working with Grasshopper, you can easily use gh-python-remote
to connect Grasshopper with Jupyter Notebook.
However, if you're working directly with the Revit API, you can now use the open-source bim-net-interactive by Joel Waldheim Saury. This is a powerful tool that helps you connect Revit with Jupyter Notebook easily and effectively, with the latest connection source code under the C# language at the time of writing.
To connect Revit with Jupyter Notebook, you need to follow these steps:
Download and install bim-net-interactive. Installing ensures that you've correctly built the Revit version and .NET Framework.
In Revit: Click "Add-ins" > NET Interactive > Show Dockable Pane. Press the "start" button.
- Install the .NET Interactive Jupyter Notebook extension by running the following command in your terminal:
dotnet tool install -g Microsoft.dotnet-interactive
Install extension for Jupyter Notebook and Polyglot Notebooks
Open Jupyter Notebook and connect to Revit through
bim-net-interactive
. Then connect to Autodesk Revit by using the #connect directive.But first, you need to install the RevitInteractive package by running the following command in your Jupyter Notebook:
#r "nuget:RevitInteractive"
#!connect revit --kernel-name revit24 --revit-version 2024
TIP
Depending on the version of Revit you are using, you can change the --revit-version
parameter accordingly.
When a connection is established, look in the variable view and you'll find variables associated with the current context or model. The variable view shows variables available for referencing and sharing.
Below we have added a C#-cell but is executing the code in Revit by using #!revit24-directive.
#!revit24
var collector = new FilteredElementCollector(doc, uidoc.ActiveView.Id);
var listOfElements = collector
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent()
.ToElements();
display(listOfElements.Count());
Let's try to get the ProjectInformation from the current model.
#!revit24
display(doc.ProjectInformation);
Let's try to pick an object element and see the element information:
#!revit24
var refers = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "Select elements to refer");
var element = doc.GetElement(refers);
display(element);
You can see the documentation example at bim-net-interactive.
The Future of Revit API and Jupyter Notebook
Revit API is becoming increasingly powerful and flexible, allowing you to interact with data, designs, and manage construction projects more efficiently and flexibly. This opens up countless opportunities related to data analysis, AI, Machine Learning, and much more.
Integration between Chatbots and Revit API enables you to interact with data, designs, and manage construction projects more easily and effectively.
Utilizing multiple languages, this allows you to comfortably choose your preferred programming language while flexibly connecting with rich libraries from different programming language ecosystems.
Training and learning about Revit API and Jupyter Notebook.
Data Exchange and Analysis with Revit API and Jupyter Notebook.
Use power of Libray in FSharp language to Analyze and Visualize data in Revit.
You now allready have the idea for your next project, right?
...