AI-Powered Python nodes in Dynamo without programming knowledge
Example: Filtering walls by their associated level name

AI-Powered Python nodes in Dynamo without programming knowledge

Creating scripts in Dynamo has never been faster or more efficient. I have struggled in the past with Python scripting in Dynamo, but luckily, that's no longer a major obstacle.

Why?

Because AI-powered tools like ChatGPT can now generate Python code for you — all you have to do is paste it into the Python node in Dynamo.

The only skill you really need now is knowing how to ask ChatGPT the right questions.

In this article, I’ve collected the most important tips for formulating requests that lead to correct and functional Python scripts for Dynamo.


1. Define the environment

Start by telling ChatGPT that you're working in Revit, Dynamo, and the Python Node environment. This context helps the AI understand which API and libraries to reference.


2. Mention inputs and outputs

Python nodes in Dynamo work with IN (input) and OUT (output). Be sure to include:

  • What goes into the node (e.g., a list of walls, strings, geometry)
  • What you expect as output (e.g., filtered elements, coordinates, booleans)

Article content
Python Script Node in Dynamo Revit

3. Object.Type node in Dynamo

Use Object.Type node in Dynamo to check the type of your input. Mention this in your request to avoid type mismatch errors in the generated script.


Article content
Object.Type Node in Dynamo Revit

4. Don’t forget about imports

Every Python script in Dynamo needs some default Revit API imports to function correctly. These usually include:

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

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *        

Without these, your script won’t interact with Revit properly. If needed, ask ChatGPT to include or fix missing imports.


5. Always check your IN and OUT

Make sure the script uses IN[0], IN[1]....(depends how many inputs you have), for input variables and OUT for the output. If ChatGPT forgets to include them, ask it to fix the node structure.


6. If It doesn’t work – debug together

If the code doesn’t work, don’t give up. Just tell ChatGPT what’s wrong — share the error or describe the behavior. It can help you debug the script quickly.


If you or your company need help with AI-powered Dynamo workflows or Revit automation, feel free to reach out — I’m happy to support you.


Happy scripting and debugging!


Here’s a sample script that filters walls by their associated level name:

I am working in Dynamo for Revit and I need a Python script that runs in a Python node. The node has two inputs: the first input (IN[0]) is a list of Walls from Revit, and the second input (IN[1]) is a string with the name of a Level (e.g., 'Level 1'). I want the script to output only the walls that belong to that specified level. Please include all the necessary Revit API imports, and use UnwrapElement to convert elements from Dynamo to Revit API. The result should be a list of filtered wall elements in OUT.
# Import necessary Dynamo and Revit API modules
import clr
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

# Inputs
walls = IN[0]  # List of Walls
level_name = IN[1]  # Name of the level (string)

# Unwrap elements
walls = [UnwrapElement(wall) for wall in walls]

# Get the current document
doc = DocumentManager.Instance.CurrentDBDocument

# Filtered walls list
filtered_walls = []

# Loop through each wall and check its level
for wall in walls:
    # Get the level ID of the wall
    level_id = wall.LevelId
    # Get the Level element
    level = doc.GetElement(level_id)
    # Compare its name to the target level name
    if level and level.Name == level_name:
        filtered_walls.append(wall)

# Output
OUT = filtered_walls        

Thanks Oleksandr, for this high value insight!

To view or add a comment, sign in

More articles by Oleksandr Khabailiuk

  • 3+ Levels of Revit Proficiency

    Based on my experience working with Revit in five large offices in Munich, Germany, I would like to share my insights…

  • The Problem with BIM Position Titles

    The BIM process is complex and often not fully implemented in many offices that claim to use Building Information…

Others also viewed

Explore content categories