CadQuery is an intuitive, easy-to-use Python module for building parametric 3D CAD models. Using CadQuery, you can write short, simple scripts that produce high quality CAD models. It is easy to make many different objects using a single script that can be customized.
CadQuery is often compared to OpenSCAD. Like OpenSCAD, CadQuery is an open-source, script based, parametric model generator. However, CadQuery stands out in many ways and has several key advantages:
- The scripts use a standard programming language, Python, and thus can benefit from the associated infrastructure. This includes many standard libraries and IDEs.
- CadQuery's CAD kernel Open CASCADE Technology (OCCT) is much more powerful than CGAL. Features supported natively by OCCT include NURBS, splines, surface sewing, STL repair, STEP import/export, and other complex operations, in addition to the standard CSG operations supported by CGAL
- Ability to import/export STEP and the ability to begin with a STEP model, created in a CAD package, and then add parametric features. This is possible in OpenSCAD using STL, but STL is a lossy format.
- CadQuery scripts require less code to create most objects, because it is possible to locate features based on the position of other features, workplanes, vertices, etc.
- CadQuery scripts can build STL, STEP, and AMF faster than OpenSCAD.
- Build 3D models with scripts that are as close as possible to how you would describe the object to a human.
- Create parametric models that can be very easily customized by end users.
- Output high quality (loss-less) CAD formats like STEP and DXF in addition to STL, VRML and AMF.
- Provide a non-proprietary, plain text model format that can be edited and executed with only a web browser.
- Offer advanced modeling capabilities such as fillets, curvelinear extrudes, parametric curves and lofts.
- Build nested assemblies out of individual parts and other assemblies.
Why this fork
The original version of CadQuery was built on the FreeCAD API. This was great because it allowed for fast development and easy cross-platform capability. However, we eventually started reaching the limits of the API for some advanced operations and selectors. This 2.0 version of CadQuery is based directly on a Python wrapper of the OCCT kernel. This gives us a great deal more control and flexibility, at the expense of some simplicity and having to handle the cross-platform aspects of deployment ourselves. We believe this is a worthwhile trade-off to allow CadQuery to continue to grow and expand in the future.
To quickly play around with CadQuery and see it's capabilities, see the CQ-editor GUI manual.
If you want to use CadQuery for your own project, keep reading:
It is currently possible to use CadQuery for your own projects in 3 different ways:
- Using the CQ-editor GUI
- From a Jupyter notebook
- As a standalone library
The easiest way to install CadQuery and its dependencies is using conda, which is included as part of an Anaconda/Miniconda installation. See the next section for an alternative to a full install of Anaconda that may be preferable to some users. The steps to install cadquery are as follows:
# Set up a new environment conda create -n cadquery # Activate the new environment conda activate cadquery # CadQuery development is moving quickly, so it is best to install the latest version from GitHub master conda install -c conda-forge -c cadquery cadquery=master
For those who are interested, the OCP repository contains the current OCCT wrapper used by CQ.
Alternative Anaconda Installation Method
For those unfamiliar (or uncomfortable) with Anaconda, it is probably best to install Miniconda to a local directory and to avoid running
conda init. After performing a local directory installation, Miniconda can be activated via the [scripts,bin]/activate scripts. This will help avoid polluting and breaking the local Python installation. In Linux, the local directory installation method looks something like this:
# Install the script to ~/miniconda wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh bash miniconda.sh -b -p $HOME/miniconda # To activate and use Miniconda source $HOME/miniconda/bin/activate
CQ-editor is an IDE that allows users to edit CadQuery model scripts in a GUI environment. It includes features such as:
- A graphical debugger that allows you to step through your scripts.
- A CadQuery stack inspector.
- Export to various formats, including STEP and STL, directly from the menu.
The installation instructions for CQ-editor can be found here.
CadQuery supports Jupyter notebook out of the box using the jupyter-cadquery extension created by @bernhard-42:
Standalone Stable Version
CadQuery was built to be used as a Python library without any GUI. This makes it great for use cases such as integration into servers, or creating scientific and engineering scripts. Use Anaconda/Miniconda to install CadQuery, and then add
import cadquery to the top of your Python scripts. If the stable version of CadQuery is desired, the following command will install it. However, be aware that the stable version can fall significantly behind the current state of CadQuery, so in many cases the
master installation method at the beginning of the Getting Started section is preferable.
conda install -c conda-forge -c cadquery cadquery=2
You can find the full CadQuery documentation at cadquery.readthedocs.io.
We also have a Google Group to make it easy to get help from other CadQuery users. We want you to feel welcome and encourage you to join the group and introduce yourself. We would also love to hear what you are doing with CadQuery.
There is a Discord channel as well. A big thanks goes to the Elmer team for hosting us.
Projects using CadQuery
Here are just a few examples of how CadQuery is being used.
FxBricks Lego Train System
FxBricks uses CadQuery in the product development pipeline for their Lego train system. FxBricks has also given back to the community by creating documentation for their CAD pipeline. They have also assembled cq-kit, a library containing utility classes and functions to extend the capabilities of CadQuery. Thanks to @michaelgale and @fx-bricks for this example.
Hexidor Board Game Development
Hexidor is an expanded take on the Quoridor board game, and the development process has been chronicled here. CadQuery was used to generate the game board. Thanks to Bruce for this example.
Thanks to @marcus7070 for this example from here.
3D Printed Resin Mold
Thanks to @eddieliberato for sharing this example of an anti-kink resin mold for a cable.