PyRx icon indicating copy to clipboard operation
PyRx copied to clipboard

How to Debug with VSC

Open royccg opened this issue 8 months ago • 4 comments

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. Image

I entered the following configuration in launch.json' in vsc.

Image

Image

royccg avatar May 23 '25 02:05 royccg

I haven’t seen this before, are you running from a VENV by any chance?

CEXT-Dan avatar May 23 '25 04:05 CEXT-Dan

I'm guessing its a path issue in AutoCAD, run PYCMDPROMPT

Image

see it the paths match up to what debugpy sees

CEXT-Dan avatar May 23 '25 05:05 CEXT-Dan

I'm guessing its a path issue in AutoCAD, run PYCMDPROMPT

Image

see it the paths match up to what debugpy sees

same path Image

royccg avatar May 23 '25 09:05 royccg

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)
        

CEXT-Dan avatar May 23 '25 12:05 CEXT-Dan

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

Image Is that wrong?

royccg avatar May 25 '25 12:05 royccg

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.

CEXT-Dan avatar May 25 '25 13:05 CEXT-Dan

@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

CEXT-Dan avatar May 25 '25 13:05 CEXT-Dan

Apparently I added this 😁 I've removed it

CEXT-Dan avatar May 25 '25 13:05 CEXT-Dan

@royccg comment that line or use the startdebug above, it should be fixed in the next release

CEXT-Dan avatar May 25 '25 13:05 CEXT-Dan

@royccg comment that line or use the startdebug above, it should be fixed in the next release

Thank a lot. 😄

royccg avatar May 25 '25 14:05 royccg