Skip to content

Execution PythonDebugging

Truong Giang Vu edited this page May 31, 2026 · 1 revision

Python Debugging With VSCode

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.

Python Debugger Demo

Quick Start

  1. Open Revit with RevitDevTool loaded.
  2. Open your script folder in VSCode.
  3. Add a VSCode debug attach configuration.
  4. Set breakpoints in your Python script.
  5. Start the VSCode debugger.
  6. Run the script from RevitDevTool.
  7. Inspect variables when execution pauses.

VSCode Launch Configuration

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.

Sample Script

debugpy_script.py

You can also debug normal scripts such as:

Debugging A Revit Collector

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(...).

Debugging Patterns

Element Collection

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")

Parameter Access

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 0

Selection

Use breakpoints after user selection to inspect the selected reference and element.

ref = uidoc.Selection.PickObject(UI.Selection.ObjectType.Element)
element = doc.GetElement(ref)

Common Problems

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

Related

Clone this wiki locally