Using Visual Studio as Python editor
-
- Posts: 6
- Joined: Tue Jun 21, 2016 2:04 pm
Using Visual Studio as Python editor
I am new to FreeCAD (and Python). My experience is using C# with Visual Studio. My problem: typing in all commands to create objects in the python console is tedious and the next day all my scripting is lost. I hoped to write my python scripts/code in VS (2015) and execute them in FreeCAD. Opening the *.py samples in VS is simple but VS keeps complaining about not able to find dependencies like Part or FreeCAD. Am I thinking the right way? missing anything?
I read I should append my FreeCAD data:
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.6704 (Git)
Build type: Release
Branch: releases/FreeCAD-0-16
Hash: 0c449d7e8f9b2b1fb93e3f8d1865e2f59d7ed253
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
I read I should append my FreeCAD data:
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.6704 (Git)
Build type: Release
Branch: releases/FreeCAD-0-16
Hash: 0c449d7e8f9b2b1fb93e3f8d1865e2f59d7ed253
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
Re: Using Visual Studio as Python editor
hi
for macro Python use the editor
mario
for macro Python use the editor

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
My macros on Gist.github here complete macros Wiki and forum.
-
- Posts: 6
- Joined: Tue Jun 21, 2016 2:04 pm
Re: Using Visual Studio as Python editor
Thanks!
Meanwhile watched this on YouTube, very good: https://www.youtube.com/playlist?list=P ... 26cn9idJrj
Meanwhile watched this on YouTube, very good: https://www.youtube.com/playlist?list=P ... 26cn9idJrj
Re: Using Visual Studio as Python editor
What? That's like telling me to use vi as my text editor instead of Notepad++! Seriously though, I have the same idea using visual studio 2017 for macro programming (AND testing). I just think it would have more better options than running the macro editor in freecad. I don't even necessarily need access to the freecad workbenches for now, but I need a bit more than I currently have. I setup a custom python environment to point to the needed items inside the freecad installation folder, but it would seem that not all the installed packages are showing up (the ones under FreeCAD_0.19\bin\Lib\site-packages folder. Perhaps I have to modify the PYTHONPATH variable to include other locations? One of the modules I call in my first macro is PySide. It works from Freecad, but VS2017 doesn't know where it is (I found it in the Ext folder right under the main Freecad folder. But how do I reference that? Then would also need to add the Mod folder for all the workbenchs.
Re: Using Visual Studio as Python editor
I did a print(os.environ) from inside Freecad, and the PATH variable looks to have everything I would need to somehow add to my custom python env. for Freecad. Is there a script somewhere inside freecad that sets that all up?
'PATH': 'E:\\FreeCAD_0.19\\bin\\lib\\site-packages\\PySide2;E:\\FreeCAD_0.19\\bin;E:\\FreeCAD_0.19\\Mod\\AddonManager;
E:\\FreeCAD_0.19\\Mod\\Arch;E:\\FreeCAD_0.19\\Mod\\Complete;E:\\FreeCAD_0.19\\Mod\\Draft;
E:\\FreeCAD_0.19\\Mod\\Drawing;E:\\FreeCAD_0.19\\Mod\\Fem;E:\\FreeCAD_0.19\\Mod\\Idf;
E:\\FreeCAD_0.19\\Mod\\Image;E:\\FreeCAD_0.19\\Mod\\Import;E:\\FreeCAD_0.19\\Mod\\Inspection;
E:\\FreeCAD_0.19\\Mod\\Material;E:\\FreeCAD_0.19\\Mod\\Measure;E:\\FreeCAD_0.19\\Mod\\Mesh;
E:\\FreeCAD_0.19\\Mod\\MeshPart;E:\\FreeCAD_0.19\\Mod\\OpenSCAD;E:\\FreeCAD_0.19\\Mod\\Part;
E:\\FreeCAD_0.19\\Mod\\PartDesign;E:\\FreeCAD_0.19\\Mod\\Path;E:\\FreeCAD_0.19\\Mod\\Points;
E:\\FreeCAD_0.19\\Mod\\Raytracing;E:\\FreeCAD_0.19\\Mod\\ReverseEngineering;
E:\\FreeCAD_0.19\\Mod\\Robot;E:\\FreeCAD_0.19\\Mod\\Show;
E:\\FreeCAD_0.19\\Mod\\Sketcher;E:\\FreeCAD_0.19\\Mod\\Spreadsheet;E:\\FreeCAD_0.19\\Mod\\Start;
E:\\FreeCAD_0.19\\Mod\\Surface;E:\\FreeCAD_0.19\\Mod\\TechDraw;E:\\FreeCAD_0.19\\Mod\\Test;
E:\\FreeCAD_0.19\\Mod\\Tux;E:\\FreeCAD_0.19\\Mod\\Web;C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\A2plus;
C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\Assembly4;
C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\BOLTSFC;
C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\CommandPanel;
C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\fasteners;
C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\parts_library;
C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\Silk;
C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\workfeature;
C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\workfeature-macro;
+more system stuff
'PATH': 'E:\\FreeCAD_0.19\\bin\\lib\\site-packages\\PySide2;E:\\FreeCAD_0.19\\bin;E:\\FreeCAD_0.19\\Mod\\AddonManager;
E:\\FreeCAD_0.19\\Mod\\Arch;E:\\FreeCAD_0.19\\Mod\\Complete;E:\\FreeCAD_0.19\\Mod\\Draft;
E:\\FreeCAD_0.19\\Mod\\Drawing;E:\\FreeCAD_0.19\\Mod\\Fem;E:\\FreeCAD_0.19\\Mod\\Idf;
E:\\FreeCAD_0.19\\Mod\\Image;E:\\FreeCAD_0.19\\Mod\\Import;E:\\FreeCAD_0.19\\Mod\\Inspection;
E:\\FreeCAD_0.19\\Mod\\Material;E:\\FreeCAD_0.19\\Mod\\Measure;E:\\FreeCAD_0.19\\Mod\\Mesh;
E:\\FreeCAD_0.19\\Mod\\MeshPart;E:\\FreeCAD_0.19\\Mod\\OpenSCAD;E:\\FreeCAD_0.19\\Mod\\Part;
E:\\FreeCAD_0.19\\Mod\\PartDesign;E:\\FreeCAD_0.19\\Mod\\Path;E:\\FreeCAD_0.19\\Mod\\Points;
E:\\FreeCAD_0.19\\Mod\\Raytracing;E:\\FreeCAD_0.19\\Mod\\ReverseEngineering;
E:\\FreeCAD_0.19\\Mod\\Robot;E:\\FreeCAD_0.19\\Mod\\Show;
E:\\FreeCAD_0.19\\Mod\\Sketcher;E:\\FreeCAD_0.19\\Mod\\Spreadsheet;E:\\FreeCAD_0.19\\Mod\\Start;
E:\\FreeCAD_0.19\\Mod\\Surface;E:\\FreeCAD_0.19\\Mod\\TechDraw;E:\\FreeCAD_0.19\\Mod\\Test;
E:\\FreeCAD_0.19\\Mod\\Tux;E:\\FreeCAD_0.19\\Mod\\Web;C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\A2plus;
C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\Assembly4;
C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\BOLTSFC;
C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\CommandPanel;
C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\fasteners;
C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\parts_library;
C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\Silk;
C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\workfeature;
C:\\Users\\Bob\\AppData\\Roaming\\FreeCAD\\Mod\\workfeature-macro;
+more system stuff
Re: Using Visual Studio as Python editor
Hi Bob,
I'm on Ubuntu, but I guess the steps would be similar on Windows
You can modify the PYTHONPATH or modify it at the top of the script using sys.path.append('/your/path'). But I'm not a fan of either of those options
I'm guessing you're working in a python virtual environment. In that case you have to do is add the paths to your external dependencies as pth files to the site packages
In other words:
make a file called /path/to/your/venv/lib/python3.6/site-packages/freecad.pth which should contain the paths to the external freecad libraries (for me it looks like:
/usr/lib/freecad-python3/lib
/usr/share/freecad/Mod
Afterwards, you should be able to import it without messing with the environment variables
I'm on Ubuntu, but I guess the steps would be similar on Windows
You can modify the PYTHONPATH or modify it at the top of the script using sys.path.append('/your/path'). But I'm not a fan of either of those options
I'm guessing you're working in a python virtual environment. In that case you have to do is add the paths to your external dependencies as pth files to the site packages
In other words:
make a file called /path/to/your/venv/lib/python3.6/site-packages/freecad.pth which should contain the paths to the external freecad libraries (for me it looks like:
/usr/lib/freecad-python3/lib
/usr/share/freecad/Mod
Afterwards, you should be able to import it without messing with the environment variables
Re: Using Visual Studio as Python editor
and why not ? all my macros (see my signature Gist) are made only with the FreeCAD editor

the only problem there is no search function in the editor
or see eric - python, eclipse and other
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
My macros on Gist.github here complete macros Wiki and forum.
Re: Using Visual Studio as Python editor
My main problem with the built in editor is that I am currently doing alot of testing, using print statements, which all appear to go to the tiny report window. I suppose I could just resize that window. Not sure why the printing doesn't happen in the python console window? If I type a print command in the python console, the output prints right in the console window, not the report view?
Re: Using Visual Studio as Python editor
Checkout: FreeCAD External Editor With Code – OSS: https://pythoncvc.net/?p=869
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
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
Re: Using Visual Studio as Python editor
Looks interesting! I'm going to try it out. Do you know offhand if the .env file setup works basically the same on Windows as shown on that page for linux (of course using slightly different path syntax)?Kunda1 wrote: ↑Fri Feb 07, 2020 12:22 pm Checkout: FreeCAD External Editor With Code – OSS: https://pythoncvc.net/?p=869