FreeCAD Part makeBox Function in Python Scripts

The Part.makeBox function in FreeCAD is a core scripting method used to programmatically generate 3D rectangular cuboids (boxes) within the application's Python environment. This article explains the primary purpose of Part.makeBox, details its syntax and parameters, demonstrates how it integrates into automated 3D modeling workflows, and highlights common use cases such as Boolean operations and automated geometry generation.

Primary Purpose of Part.makeBox

In FreeCAD, the Part.makeBox method belongs to the Part module, which provides the foundation for Constructive Solid Geometry (CSG) and boundary representation (B-rep) shapes. The primary purpose of Part.makeBox is to create a basic solid box primitive entirely via code, eliminating the need to manually sketch a rectangle and pad it using the graphical user interface (GUI).

By generating an underlying OpenCASCADE topological data structure (a TopoDS_Shape), Part.makeBox provides a solid that is immediately ready for geometric analysis, export, or further algorithmic modification.

Syntax and Parameters

The standard syntax for the function is:

Part.makeBox(length, width, height, [pnt, dir])
  • length (float): The dimension along the X-axis.
  • width (float): The dimension along the Y-axis.
  • height (float): The dimension along the Z-axis.
  • pnt (FreeCAD.Vector, optional): The base point from which the box originates. Defaults to the global origin (0, 0, 0).
  • dir (FreeCAD.Vector, optional): The direction vector defining the orientation of the height dimension. Defaults to (0, 0, 1).

How It Works in Practice

When called, Part.makeBox returns a raw Part.Shape object in memory. To make this shape visible within a FreeCAD project, it must either be displayed directly or assigned to an active document object.

A typical implementation looks like this:

import FreeCAD
import Part

# Create the solid shape in memory (10mm x 20mm x 30mm)
box_shape = Part.makeBox(10.0, 20.0, 30.0)

# Option 1: Quickly display the shape in the active document
Part.show(box_shape)

# Option 2: Bind the shape to a formal document object
doc = FreeCAD.ActiveDocument or FreeCAD.newDocument("BoxDesign")
box_obj = doc.addObject("Part::Feature", "CustomBox")
box_obj.Shape = box_shape
doc.recompute()

Common Use Cases in Scripting

  • Boolean Operations: Cubes and rectangular volumes generated via makeBox are commonly used as cutters or additions. Scripts often subtract a box from another model using .cut(), or combine it using .fuse().
  • Stock Material Definition: In automated computer-aided manufacturing (CAM) or CNC workflows, Part.makeBox can quickly define the bounding envelope or stock block of raw material based on the dimensions of a finished part.
  • Algorithmic and Parametric Design: When generating complex structures—such as grid arrays, enclosures, ribs, or modular framing—scripts can rapidly instantiate hundreds of precisely dimensioned boxes without GUI overhead.
  • Bounding Boxes and Clearances: Developers use makeBox to model keep-out zones, clearance volumes, and component boundaries within larger mechanical assemblies.