How to Debug with VSC
First of all, thank you for providing pyrx. Can you provide more information about debugging in vsc?
in autocad, I entered the command of pydebug, but returned the following error message.
I entered the following configuration in launch.json' in vsc.
I haven’t seen this before, are you running from a VENV by any chance?
I'm guessing its a path issue in AutoCAD, run PYCMDPROMPT
see it the paths match up to what debugpy sees
I'm guessing its a path issue in AutoCAD, run PYCMDPROMPT
see it the paths match up to what debugpy sees
same path
We don’t do anything special with pydebug, we just call it to start the listener.
Try this,
- save and pyload this code.
- Run the command startdebug
- in vscode choose run - > start debugging
- back in CAD run the command debugme
import wx
import os
import sys
import debugpy
import traceback
from pyrx import Ap, Ed
print("Added new command startdebug, type startdebug at the prompt: ")
@Ap.Command()
def startdebug():
try:
result = wx.MessageDialog(
None,
"This will start the debug Listener for the session"
+ "\n"
+ "Now is a good time to run your debugger from vs code:",
"Confirm",
wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION,
).ShowModal()
if result != wx.ID_YES:
return
#config
DEBUG_HOST = "127.0.0.1"
DEBUG_PORT = 5678
PYTHON_PATH = sys.base_prefix + "\\python.exe"
os.environ["PYDEVD_DISABLE_FILE_VALIDATION"] = "1"
debugpy.configure(python=PYTHON_PATH)
debugpy.listen((DEBUG_HOST, DEBUG_PORT))
print("dubugger running...")
except Exception as err:
traceback.print_exception(err)
print("Added new command debugme, type debugme at the prompt after the debugger is running: ")
@Ap.Command()
def debugme() -> None:
try:
debugpy.breakpoint()
res = Ed.Editor.getPoint("\nGetPoint")
print("res")
except Exception as err:
traceback.print_exception(err)
We don’t do anything special with pydebug, we just call it to start the listener.
Try this,
- save and pyload this code.
- Run the command startdebug
- in vscode choose run - > start debugging
- back in CAD run the command debugme
import wx import os import sys import debugpy import traceback from pyrx import Ap, Ed
print("Added new command startdebug, type startdebug at the prompt: ") @Ap.Command() def startdebug(): try: result = wx.MessageDialog( None, "This will start the debug Listener for the session" + "\n" + "Now is a good time to run your debugger from vs code:", "Confirm", wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION, ).ShowModal()
if result != wx.ID_YES: return #config DEBUG_HOST = "127.0.0.1" DEBUG_PORT = 5678 PYTHON_PATH = sys.base_prefix + "\\python.exe" os.environ["PYDEVD_DISABLE_FILE_VALIDATION"] = "1" debugpy.configure(python=PYTHON_PATH) debugpy.listen((DEBUG_HOST, DEBUG_PORT)) print("dubugger running...") except Exception as err: traceback.print_exception(err)print("Added new command debugme, type debugme at the prompt after the debugger is running: ")
@Ap.Command() def debugme() -> None: try: debugpy.breakpoint() res = Ed.Editor.getPoint("\nGetPoint") print("res") except Exception as err: traceback.print_exception(err)
This is OK, Thanks a lot.
I found inconsistent codes in the file of PyRxDebug.py.
debugpy.wait_for_client()
Is that wrong?
Hi,
If you comment that line, does the pydebug command work? Both work for me
Debugpy docs show to use ‘debugpy.wait_for_client()’ It may not be necessary in an embedded context.
@gswifort do you think we need this line if it is indeed the culprit?
- The way I see it, the user is already command context when starting the listener and will need to execute a new command to debug
- AutoCAD is blocked, if the command is entered by mistake or attach fails, there's no way for them to save their work
Apparently I added this 😁 I've removed it
@royccg comment that line or use the startdebug above, it should be fixed in the next release
@royccg comment that line or use the startdebug above, it should be fixed in the next release
Thank a lot. 😄