Debugging posts with VSCode

I see there is, in the macro menu, Macro>Attach to remote debugger

Does this allow stepping in and breakpoints in an _post.py?

And, any idea how to get VSCode to resolve the ‘import FreeCAD’, etc. lines?

(Yes, I’m a hack, I admit it. :mrgreen: )

This is from the German sub-forum: https://forum.freecadweb.org/viewtopic.php?f=13&t=43681#p372293

Thanks @wmayer.

I read through the German forum post and through the destructions at https://wiki.freecadweb.org/Debugging

Unfortunately, it just created more questions…maybe they are obvious if one has done this before, but my python experience is in creating my own, rather large, application a few years back using the PyCharm IDE. With that project in the rear view mirror and having switched to VSCode since I now do more in the ESP32 and Arduino land I’ve not had to deal with this sort of attaching to other applications to debug.

I see that the

import ptvsd...

is to added to the beginning of the .py file to be debugged.

I don’t get how to add the confuration to VSCode. It appears the instructions in the FC wiki are for an earlier version of VSCode, and “Add Configuration” open the .json file for…well, I suppose whatever file is open in VSCode. (whether the _post.py file is open or any .py file). So basically I have no idea where the “configurations” json code shown in the wiki is supposed to go. Is it added to the json that’s already there? How do I know or specify which configuration to use? (I’m sure this is part of learning how VSCode works…but, their wiki isn’t much help there either. :cry:

And, since the _post.py file is open in VSCode and can’t resolve the

import FreeCAD , from FreeCAD...

running debug in VSCode just throws a “No module named FreeCAD” error.

Any pointers appreciated…mac goes off to grok VSCode & FreeCAD. :sunglasses:

Ok, I tried stuff until it made the connection.

Now the FC python console output show up in VSCode.

But, if I set a breakpoint in VSCode it (VSCode) says the breakpoint is in a nonexistent module. :confused:

And, VSCode still can’t

import FreeeCAD

I had the same problem yesterday and it works with the following settings for me:
launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Remote Attach",
            "type": "python",
            "request": "attach",
            "redirectOutput": true,
            "connect": {
                "host": "0.0.0.0",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "/home/devel/.FreeCAD/Macro/",
                    "remoteRoot": "/home/devel/.FreeCAD/Macro/"
                }
            ]
        }
    ]
}

your.FCMacro:

import ptvsd
print("Waiting for debugger attach")
ptvsd.enable_attach(address=('0.0.0.0', 5678))
ptvsd.break_into_debugger()

I then set my breakpoints and start debugging in vscode. After that I run the script in FreeCAD.

Greetings Alex