Please demonstrate using a remote text editor to substitute the Python editor in FreeCAD

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
User avatar
Kunda1
Posts: 8851
Joined: Thu Jan 05, 2017 9:03 pm

Re: Please demonstrate using a remote text editor to substitute the Python editor in FreeCAD

Postby Kunda1 » Mon Oct 05, 2020 7:10 am

Cyril wrote:
Sun Oct 04, 2020 3:33 pm
I have updated my article with enhanced auto-completion using freecad-stubs.
Awesome!
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
hsbank
Posts: 1
Joined: Wed Oct 07, 2020 6:29 am

Re: Please demonstrate using a remote text editor to substitute the Python editor in FreeCAD

Postby hsbank » Wed Oct 07, 2020 6:53 am

Based on Cyril's explanation, I wanted to add Windows version. I have seen a few different questions from Windows perspective. I will try to keep as generic as possible in terms of folder representation. As Cyril explained in the video, create .env file and include the followings in .env file.

Code: Select all

FREECAD_LIB=../FreeCAD_0.19.22522/lib
FREECAD_MOD=../FreeCAD_0.19.22522/Mod
FREECAD_STUBS=../FreeCAD_0.19.22522/freecad-stubs/out
PYTHONPATH=${FREECAD_STUBS};${FREECAD_Mod};${FREECAD_LIB};${PYTHONPATH}
That said the project parent folder is the same location as the FreeCAD_0.19.22522 AppImage (Conda binary). Therefore, I have ../ structure in .env. Alternatively, you can write the lines below. Here, <WHEREVER YOU HAVE YOUR FREECAD> is the installation location.

Code: Select all

FREECAD_LIB=C:\\<WHEREVER YOU HAVE YOUR FREECAD>\\FreeCAD_0.19.22522\\lib
FREECAD_MOD=C:\\<WHEREVER YOU HAVE YOUR FREECAD>\\FreeCAD_0.19.22522\\Mod
FREECAD_STUBS=C:\\<WHEREVER YOU HAVE YOUR FREECAD>\\FreeCAD_0.19.22522\\freecad-stubs/out
PYTHONPATH=${FREECAD_STUBS};${FREECAD_Mod};${FREECAD_LIB};${PYTHONPATH}
I included stubs after downloading zip file from GitHub and opening the archive in FreeCAD installation folder as /freecad-stubs. In Windows 10, while writing PYTHONPATH you need to use ; instead of : . After adding .env file you need to restart VS Code.

I also use .vscode/settings.json for my project folder.

Code: Select all

{
    "terminal.integrated.env.windows": {
        "PYTHONPATH": "${env:PYTHONPATH};${workspaceFolder}/src",
    },
    "python.envFile": "${workspaceFolder}/.env"
}
In settings.json, you see that I have /src folder in which I keep my python scripts and modules that I developed. Having settings.json is not a must unless you would like to keep your developed python code -or module- in a separate folder.

Thank you Cyril for the video.
drmacro
Posts: 2017
Joined: Sun Mar 02, 2014 4:35 pm

Re: Please demonstrate using a remote text editor to substitute the Python editor in FreeCAD

Postby drmacro » Wed Oct 07, 2020 10:43 am

I started modifying the grbl post yesterday in VS Code. I like linting and the modified file gets read each time I run it in Path.

But, i definitely need to find the forum post about setting up for debugging. Would be nice to be able to checkout variables at runtime. :roll:
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."

My beginners, written treatise: Learning FreeCAD
User avatar
Cyril
Posts: 126
Joined: Wed Aug 23, 2017 5:04 pm
Location: Geneva (Switzerland)
Contact:

Re: Please demonstrate using a remote text editor to substitute the Python editor in FreeCAD

Postby Cyril » Wed Oct 07, 2020 4:42 pm

drmacro wrote:
Wed Oct 07, 2020 10:43 am
I started modifying the grbl post yesterday in VS Code. I like linting and the modified file gets read each time I run it in Path.

But, i definitely need to find the forum post about setting up for debugging. Would be nice to be able to checkout variables at runtime. :roll:
You are in the right thread :lol: (see previous posts)

I am still using ptvsd but yesterday I saw that vscode has a new debugger called debugpy. I am currently looking at it to debug Blender addons.
I blog about HVAC / BIM / Energy : pythoncvc.net. If you like you can follow the RSS feed.
drmacro
Posts: 2017
Joined: Sun Mar 02, 2014 4:35 pm

Re: Please demonstrate using a remote text editor to substitute the Python editor in FreeCAD

Postby drmacro » Wed Oct 07, 2020 6:57 pm

I've added the python and json code as specified in the FC wiki: https://wiki.freecadweb.org/Debugging

But, am still confused about a couple things.

- what is the sequence to make the connection between FC and VSCode debugger.

- VSCode basically won't do anything because it knows not where "import FreeCAD" module resides, thus can't import.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."

My beginners, written treatise: Learning FreeCAD