Sandbox:Piffpoof3

Python IDE within FreeCAD

Python is a programming environment that is incorporated into the FreeCAD system. Using Python most operations offered by FreeCAD are available for programmatic access. Python programs for FreeCAD are usually developed to be either run on the Python console or through the Macro facility of FreeCAD (see Macro Install HowTo).

There are numerous tools available for program development in Python. The complicating factor for developing Python to use with FreeCAD are twofold: first the tools do not have any support for the numerous data structures and access points of FreeCAD; secondly they do not work "within FreeCAD". This means that you can use them to develop code outside of FreeCAD and not be able to test in the target environment; or you can develop Python in the target environment (i.e. the FreeCAD environment) but not have any support from the development tools. Neither of these is a preferable solution.

Background
Modern software development at the commercial standard is usually done using a set of tools generically referred to as 'IDE'. Typically these tools include the following 3:


 * source code editor
 * build automation tools
 * debugger

which are standard while the following are present in some IDEs but not in others:


 * intelligent code completion
 * integrated compiler, interpreter, or both
 * version control system
 * Graphical User Interface (GUI) construction
 * class browser
 * object browser
 * class hierarchy diagram

A summary of the status of these tools within FreeCAD is ('N/A' meaning 'Not Available'):

Many tools exist to support the above function for Python programming but unfortunately they do not integrate with the FreeCAD development environment.

A list of IDEs for Python is located at Integrated Development Environments for Python

Editors
A list of editors for Python for a variety of platforms is available at Python Editors

Users on Macintosh
For the Macintosh the text editor TextWrangler works well. It has code highlighting and excellent search facilities. There are options to execute jobs in Python but of course they do not work with the FreeCAD environment.

Directories
There are two directories used by FreeCAD, by default they are the same directory but they are pointed to by different callable point in FreeCAD:
 * FreeCAD.ConfigGet("UserAppData")
 * FreeCAD.ParamGet('User parameter:BaseApp/Preferences/Macro').GetString('MacroPath')

The first one "UserAppData" points to a directory where things like configuration files or other files intended for the user but not to be edited by the user may be stored.

The second one "MacroPath" points to a directory where the Python files which are macro files for FreeCAD are stored. To mark a Python file as a macro file for FreeCAD, the file extension is changed from ".py" to ".FCMacro".

By default these two directories are the same location but this is not necessary. It might be convenient to alter the location for the macro files (*.FCMacro) to a different location.

Editing files located in the "MacroPath" is straight forward, the text editor will accommodate this. For ease of use of FreeCAD Macro files, it is advisable to keep all the macro files in the directory pointed to by "MacroPath".

To alter the "MacroPath" directory, use Tools->Edit Parameters and then select Preferences/Macro/MacroPath where the text may be double-clicked and edited. Alternatively the code

Debugger

 * breakpoints


 * using global variables

Coding Framework

 * testStub

Miscellaneous Links
Some other links about IDEs for Python which might be of interest are:
 * Comparison of Python IDEs for Development
 * Choosing the Best Python IDE
 * Your Development Environment
 * PyCharm Community Edition IDE