Skip to content

Debugging macros in Visual Studio Code

Gaël Écorchard edited this page Jun 2, 2023 · 2 revisions
  1. In FreeCAD's Python console:
import ptvsd
ptvsd.enable_attach(address=('localhost', 5678))
  1. In Visual Studio Code, "Run and Debug (Ctrl+Shift+D)", "Add Configuration...", "Python", "Attach". The configuration should look like this:
{
    "configurations": [
        {
            "name": "Python: Remote Attach",
            "type": "python",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "${workspaceFolder}"
                }
            ],
            "justMyCode": true
        }
    ]
}

Note the port 5678 that is used in both applications.

More details on FreeCAD's wiki but the remoteRoot there doesn't work and setting it to a hard-coded path is not practical.

Alternatively, you can use debugpy in FreeCAD:

import debugpy
debugpy.configure(python="python")
debugpy.listen(5678)