How to Open and Use the Python Console in FreeCAD

FreeCAD is built from the ground up to be fully controlled via Python, allowing users to automate modeling tasks, build custom tools, and inspect geometric data. This guide explains how to display the integrated Python console in the FreeCAD interface, navigate its basic controls, and execute essential commands to create and manipulate 3D objects directly through code.

Opening the Python Console

By default, the Python console may be hidden depending on your chosen workbench or workspace configuration. To reveal it:

  1. Launch FreeCAD.
  2. Navigate to the top menu bar and click View.
  3. Hover over Panels.
  4. Check the box next to Python console.

The console panel will typically dock at the bottom of the FreeCAD window, alongside the "Report view." You can click and drag the panel header to undock it into a floating window or reposition it anywhere on your screen.

Console Basics and Features

The FreeCAD Python console functions like a standard interactive Python shell (REPL) with several built-in conveniences:

  • Command Prompt (>>>): Indicates the console is ready for Python expressions or statements.
  • Auto-Completion: Press Tab or Ctrl + Space while typing an object name or function to view available attributes, methods, and modules.
  • Command History: Use the Up Arrow and Down Arrow keys to cycle through previously executed commands.
  • Multi-Line Execution: Paste blocks of Python code directly into the console to run entire routines at once.

Essential Commands for Basic Modeling

To manipulate the 3D scene, you must interact with the core FreeCAD libraries. The two primary modules are FreeCAD (often aliased as App) and FreeCADGui (aliased as Gui).

1. Create a New Document

Before adding 3D objects, create or reference an active document:

import FreeCAD as App
import Part

doc = App.newDocument("ConsoleDemo")

2. Create a Primitive Shape

To create a standard geometric primitive, such as a box, add a Part object and define its dimensions:

# Add a Box object to the document
box = doc.addObject("Part::Box", "TestBox")

# Set dimensions (values are in millimeters)
box.Length = 20.0
box.Width = 30.0
box.Height = 10.0

3. Update the 3D View

Changes made via the console do not render in the viewport automatically. You must recompute the document:

doc.recompute()

4. Inspecting Existing Objects

You can quickly reference whichever object is currently selected in the Tree View:

obj = App.ActiveDocument.ActiveObject
print(obj.Name)
print(obj.Shape.Volume)

Viewing Generated Code

To learn how FreeCAD executes actions under the hood, navigate to Edit > Preferences > Python and enable the option to print GUI commands to the Python console. When enabled, actions you perform using the graphical user interface—such as clicking toolbar tools or editing dimensions—will automatically display their corresponding Python code in the console, making it easy to copy and adapt commands into your own automation scripts.