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

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

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

Post by Kunda1 »

Cyril wrote: Sun Oct 04, 2020 3:33 pm I have updated my article with enhanced auto-completion using freecad-stubs.
Awesome!
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
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

Post by hsbank »

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
Veteran
Posts: 8978
Joined: Sun Mar 02, 2014 4:35 pm

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

Post by drmacro »

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."
Cyril
Posts: 133
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

Post by Cyril »

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
Veteran
Posts: 8978
Joined: Sun Mar 02, 2014 4:35 pm

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

Post by drmacro »

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."
Modeler
Posts: 43
Joined: Fri Feb 19, 2021 4:42 pm

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

Post by Modeler »

Here is a video showing debugging FreeCAD Python macros with Visual Studio Code with all the set up that is needed. Very simple. You can even use the debugger to edit the code but I am not sure how useful it is.


phpBB [video]



PTVSD is required and is available here.

pip install ptvsd
chrisb
Veteran
Posts: 54168
Joined: Tue Mar 17, 2015 9:14 am

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

Post by chrisb »

Moved to Python forum - finally.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
chrisb
Veteran
Posts: 54168
Joined: Tue Mar 17, 2015 9:14 am

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

Post by chrisb »

Following posts were split to a new topic.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

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

Post by Kunda1 »

reupping this topic. I never got closure on this.
Note: there is alnso's effort to incorporate KTextEditor https://github.com/Alonso-JAMM/FreeCAD_KTextEditor
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Post Reply