cadquery-ocp: Open CASCADE Technology Python Wrapper
cadquery-ocp provides a low-level Python wrapper for the Open CASCADE Technology (OCCT) 3D geometry kernel, offering thin bindings to almost all OCCT C++ libraries. It is a fundamental dependency for the CadQuery parametric CAD framework and is regularly updated to react quickly to new OCCT releases. The current version is 7.9.3.1.
Warnings
- gotcha Direct usage of the OCP (OCCT C++ API) is significantly more verbose and complex than using higher-level libraries like CadQuery. It requires a strong understanding of the underlying Open CASCADE Technology C++ classes and concepts.
- gotcha Installation via `pip` can sometimes encounter issues due to complex binary dependencies, especially on less common system configurations or Python versions. `conda` is often recommended for a more robust installation experience, particularly when also installing CadQuery.
- gotcha The `cadquery-ocp` library has specific Python version requirements (>=3.10, <3.15 for version 7.9.3.1). Installing with an incompatible Python version will lead to installation failures or runtime errors.
Install
-
pip install cadquery-ocp -
conda install -c conda-forge -c cadquery ocp
Imports
- BRepPrimAPI_MakeBox
from OCP.BRepPrimAPI import BRepPrimAPI_MakeBox
- gp_Pnt
from OCP.gp import gp_Pnt
Quickstart
from OCP.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCP.gp import gp_Pnt
# Create a 10x20x30mm box starting at (0,0,0)
box_maker = BRepPrimAPI_MakeBox(gp_Pnt(0, 0, 0), 10.0, 20.0, 30.0)
ocp_shape = box_maker.Shape()
# The ocp_shape object can then be used by other OCP functions
# or converted into a CadQuery object for higher-level operations.
# Example (requires CadQuery):
# import cadquery as cq
# cq_box = cq.Shape.cast(ocp_shape)
# print(cq_box.isValid())
print(f"Created OCP shape: {ocp_shape.__class__.__name__}")