cadquery
Sketch
Workplane
Assembly

Workplane.cut()

The Workplane.cut() function in CadQuery allows you to remove material from the current workplane.

Syntax

cut(to_cut, **kwargs)

Parameters

  • to_cut: The object or list of objects to cut from the workplane.
  • **kwargs: Optional parameters to customize the cut operation. These include:
    • keep=False: If True, the original objects are kept in addition to the cut result.
    • clean=True: If True, the result will be cleaned to remove any unnecessary edges.

Returns

A new Workplane object representing the remaining geometry after the cut operation.

Usage

Cutting a Shape

To cut a shape from the current workplane, simply pass the shape object to the cut() function. For example, to cut a cylinder from the current workplane:

from cadquery import Workplane, Cylinder

result = Workplane().box(10, 10, 10).cut(Cylinder(5, 10))

This will create a 10x10x10 cube and then cut a cylinder with a radius of 5 and a height of 10 from it.

Cutting Multiple Shapes

You can also cut multiple shapes at once by passing a list of objects to the cut() function. For example, to cut a cylinder and a sphere from the current workplane:

from cadquery import Workplane, Cylinder, Sphere

cylinder = Cylinder(5, 10)
sphere = Sphere(5)

result = Workplane().box(10, 10, 10).cut([cylinder, sphere])

This will create the same 10x10x10 cube as before, and then cut a cylinder and a sphere from it.

Keeping the Original Objects

By default, the objects that are cut from the workplane are discarded. However, you can keep them by setting the keep parameter to True. For example:

from cadquery import Workplane, Cylinder

to_cut = Cylinder(5, 10)

result = Workplane().box(10, 10, 10).cut(to_cut, keep=True)

Cleaning the Result

The clean parameter can be set to False if you want to disable the cleaning of the result. For example:

from cadquery import Workplane, Cylinder

to_cut = Cylinder(5, 10)

result = Workplane().box(10, 10, 10).cut(to_cut, clean=False)

Conclusion

The Workplane.cut() function in CadQuery is a powerful tool for removing material from your models. It allows you to perform complex operations by cutting multiple shapes at once and customizing the cut behavior with optional parameters. By understanding how to use this function correctly, you can improve your workflow and create more sophisticated designs.