

These two modules can also be accessed from scripts outside of the interpreter, by the names FreeCAD and FreeCADGui respectively. Since FreeCAD is designed so that it can also be run without a Graphical User Interface (GUI), almost all its functionality is separated into two groups: Core functionality, named App, and GUI functionality, named Gui. The entry Python scripting documentation will give you a quick link to the Power users hub wiki section. Your FreeCAD window must stay open for this documentation system to work. The documentation available there depends on how much effort each module developer put into documenting his code, but Python modules have a reputation for being fairly well documented. In the FreeCAD Help menu, you'll find an entry labeled Automatic python modules documentation, which will open a browser window containing a complete, realtime-generated documentation of all Python modules available to the FreeCAD interpreter, including Python and FreeCAD built-in modules, system-installed modules, and FreeCAD additional modules.
#Python freecad examples full
To navigate through the command history, just use Up arrow or Down arrow.īy right-clicking in the interpreter window, you also have several other options, such as copy the entire history (useful when you want to experiment with things before making a full script of them), or insert a filename with complete path.
#Python freecad examples code
print(dir(App)) will show you everything inside the App module, etc.Īnother useful feature of the interpreter is the possibility to go back through the command history and retrieve a line of code that you already typed earlier. For example, typing print(dir()) will list all modules currently loaded in FreeCAD. Another more generic Python way of exploring the content of modules and classes is to use the print(dir()) command. When you select something, an associated help text (if it exists) is displayed: FreeCAD provides a very handy class browser for exploration of the FreeCAD world: When you type the name of a known class followed by a period (meaning you want to add something from that class), a class browser window opens, where you can navigate between available subclasses and methods. The screenshot below shows the Python interpreter:įrom the interpreter, you can execute Python code and browse through the available classes and functions. If you don't see the window labeled Python console as shown below, you can activate it under the View → Panels → Python console.įrom the interpreter, you can access all your system-installed Python modules, as well as the built-in FreeCAD modules, and all additional FreeCAD modules you installed later.

FreeCAD has a built-in Python interpreter.

Python is a very easy language to learn, especially because it can be run inside an interpreter, where simple commands, right up to complete programs, can be executed on the fly without the need to compile anything. If you are not familiar with Python, we recommend you search for tutorials on the internet and have a quick look at its structure. As a result, FreeCAD is probably one of the most deeply customizable engineering applications available today. Almost all parts of FreeCAD, such as the interface, the scene contents, and even the representation of this content in the 3D views, are accessible from the built-in Python interpreter or from your own scripts. FreeCAD is built from scratch to be totally controlled by Python scripts.
