-
Notifications
You must be signed in to change notification settings - Fork 0
Execution PythonDebugging
Truong Giang Vu edited this page May 31, 2026
·
1 revision
Python debugging lets you attach VSCode to a Python script running inside RevitDevTool. Use it when print debugging is too slow or when a bug only appears with real Revit API objects.

- Open Revit with RevitDevTool loaded.
- Open your script folder in VSCode.
- Add a VSCode debug attach configuration.
- Set breakpoints in your Python script.
- Start the VSCode debugger.
- Run the script from RevitDevTool.
- Inspect variables when execution pauses.
Create or update .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach RevitDevTool Python",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"justMyCode": false
}
]
}The port must match the debug port configured in RevitDevTool.
You can also debug normal scripts such as:
from Autodesk.Revit import DB
doc = __revit__.ActiveUIDocument.Document
walls = DB.FilteredElementCollector(doc).OfClass(DB.Wall).ToElements()
for wall in walls:
curve = wall.Location.Curve
length = curve.Length
print(f"Wall {wall.Id}: {length:.2f}")Useful breakpoints:
- before
FilteredElementCollector; - inside the wall loop;
- before calculations using geometry or parameters.
Useful values to inspect:
-
doc.Title; -
len(walls); -
wall.Id; -
wall.Name; -
wall.Location; -
curve.Length; - parameters returned by
wall.get_Parameter(...).
Pause after a collector runs and inspect the count before processing the elements.
elements = DB.FilteredElementCollector(doc).OfClass(DB.FamilyInstance).ToElements()
print(f"Found {len(elements)} instances")Pause after retrieving a parameter so you can check whether it exists before calling AsString(), AsDouble(), or AsInteger().
param = wall.get_Parameter(DB.BuiltInParameter.WALL_USER_HEIGHT_PARAM)
height = param.AsDouble() if param else 0Use breakpoints after user selection to inspect the selected reference and element.
ref = uidoc.Selection.PickObject(UI.Selection.ObjectType.Element)
element = doc.GetElement(ref)| Symptom | Check |
|---|---|
| Breakpoint is never hit | VSCode is attached before running the script |
| VSCode cannot connect | debug port matches RevitDevTool settings |
debugpy import fails |
Python dependencies were prepared successfully |
| Debugger attaches but file is not mapped | open the same script folder in VSCode |
| Script blocks waiting | a modal Revit selection/dialog may be active |
| Revit freezes while paused | this is expected; continue/step from VSCode |
- Run Code Overview
- Modern Python Scripting
- Python Debugging
- Python Ecosystems
- RevitDevTool And pyRevit
- Python Stub Generation
- Run .NET Add-ins
- Scripting Runtimes