CadQuery
CadQuery is an intuitive, easy-to-use Python module for building parametric 3D CAD models. It provides a fluent API for creating complex shapes and assemblies, leveraging the OpenCASCADE CAD kernel. Currently at version 2.7.0, it maintains an active development cycle with regular bugfix releases and periodic minor version updates.
Warnings
- breaking CadQuery has complex dependencies, particularly OCP (OpenCASCADE Python bindings). While Python 3.9 through 3.12 are supported for version 2.7.0, using bleeding-edge Python versions (e.g., newer than 3.12) might encounter lagging support from these underlying dependencies, leading to installation or runtime failures.
- gotcha While `pip install cadquery` is available, the official documentation and community often recommend `conda` (or installing via the `CQ-editor` GUI bundle) for managing CadQuery's complex dependencies. This can prevent common installation issues related to `OCP` on certain operating systems or Python configurations.
- gotcha CadQuery's API is designed for chaining operations (a 'fluent' API), where most methods return a *new* `Workplane` object. Directly modifying attributes of a `Workplane` or expecting side effects on previous objects in the chain can lead to unexpected behavior. Always assign the result of an operation to a variable if you need to reference that specific state.
- gotcha When integrating CadQuery with external visualization tools or GUIs like `Jupyter CadQuery`, be aware that the default view orientation (e.g., 'Z-up' vs. 'Y-up' for the 'front' plane) can change between versions of the visualization tool. This can make your models appear rotated or misaligned from expectations if explicit orientation settings are not used.
- deprecated Older CadQuery tutorials or scripts might use direct imports like `from cadquery import Workplane, Vector`, or even `from cadquery import *`. While these may still function, the recommended and more robust practice is to `import cadquery as cq` and access components via `cq.Workplane`, `cq.Vector`, etc. This prevents potential naming conflicts and clearly indicates the source of the objects.
Install
-
pip install cadquery
Imports
- Workplane
import cadquery as cq result = cq.Workplane(...)
Quickstart
import cadquery as cq
# Define dimensions for a simple box
length = 80.0
height = 60.0
thickness = 10.0
# Create a rectangular box starting on the XY plane
result = cq.Workplane("XY").box(length, height, thickness)
# If running in CQ-editor, 'result' will be automatically displayed.
# For headless use or export, you would typically save it:
# cq.exporters.export(result, "my_box.step")
# This line is for testing/headless environments to confirm an object exists
assert result.isValid()