Attaching VS Code Debugger

How do you attach the VS code debugger to run a pyRevit script?
I was looking at the dev docs and found this: https://www.notion.so/Debugger-8487200113a54725900fdffa02136d17. Is there more information on this?

Thanks!

Marking that as completede was a mistake. I fixed it to “In Progress”

Checkout the debugpy module. I’m trying to provide support using this module (that vscode uses as well) to allow vscode to remotely connect to a pyRevit command execution thread.

Work in progress :smiley:

6 Likes

Is there any update on this (I am looking into the module, but didn’t know if there was anything official)? I am currently doing print statements for debugging… :confused: probably not the best method.

I recommend checking out the Console in the rpw library as a tool for debugging as well if print statements aren’t cutting it for you.

https://revitpythonwrapper.readthedocs.io/en/latest/ui/forms.html?highlight=console#console

Hi @jbf1212 ,

did you ever get it working?
I try to create a simple button with

from rpw.ui.forms import Console

Console()

but it doesn’t work.

On the last version of pyrevit that I just installed it gives me the following Traceback:

IronPython Traceback:
Traceback (most recent call last):
 File "D:\users\[....]\script.py", line 3, in <module>
 File "C:\Users\[...]\AppData\Roaming\pyRevit-Master\pyrevitlib\rpw\ui\forms\console.py", line 111, in __init__
 File "inspect.py", line 1060, in stack
AttributeError: 'module' object has no attribute '_getframe'

I tried also with Console(stack_info=False) just to see if it changes anything, but it doesn’t.

Mostly I was trying that to get an interactive console (in alternative to RevitPythonShell) rather than use it for debugging purposes.
For that, it surely would be awesome to be able to attach the iron/cpython process to the VSCode debugger!

your simple code in a button, it works for me


I am using pyrevit Version: “4.8.11.22136+0257-wip”

Hi @Jean-Marc , thanks for the reply! This got me thinking, and I found the answer: it was a problem with the IronPython Engine.

I’m on Revit 2021; The error I posted earlier was with the default engine, while 2711 gives the following error:

Traceback (most recent call last):
 File "D:\users[...]\script.py", line 3, in <module>
 File "C:\Users\[...]\AppData\Roaming\pyRevit-Master\pyrevitlib\rpw\ui\forms\console.py", line 126, in __init__
TypeError: LoadComponent() takes exactly 3 arguments (2 given)

engine version 2710 works!

1 Like

It makes sense.
The LoadComponent() args is an issue in itself as it is used all over the place in WPF forms by many extensions (seen in pychilizer and ef-tools so far)

Hi @sanzoghenzo,

The following is noted in the RPW documentation:

Inspection of the stack requires stack frames to be enabled. If an exception is raised stating 'object has no attribute '_getframe' it means IronPython stack frames is not enabled. You can enable it by running with the -Xargument:ipy.exe -X: FullFrames file.py`.

You can also manually pass it the context like so:
Console(context=locals())
When debugging, I typically set the context to locals rather than globals, and if I need to import any globals I can just do that from the console.

2 Likes

Or you can simply use debug logging with the included pyRevit logger logger = output.get_logger()
logger.debug('something something'), and run your commands via ctrl+click that will force debug mode, even if you have any other default logging level set in pyRevit settings. That’s how we do it.