cadquery
Sketch
Workplane
Assembly

Workplane.hole()

The hole method is used in the CadQuery library to create a cutout hole in a solid object.

Method Signature

def hole(self, diameter, depth=None, tolerance=None, kind="", **kwargs):

Parameters

  • diameter: The diameter of the hole to be created in the solid object. This can either be a float value or a string that represents a valid expression that evaluates to a float. For example, "5 mm" or "0.25 inch".
  • depth (optional): The depth of the hole to be created in the solid object. This can either be a float value or a string that represents a valid expression that evaluates to a float. If not provided, the hole will be created through the entire solid object.
  • tolerance (optional): The maximum allowable deviation from the exact geometry of the hole. If not provided, a default value of 0.01mm is used.
  • kind (optional): The type of hole to create. Valid values include "simple", "counterbore" and "countersink". The default value is "simple".
  • **kwargs (optional): Additional keyword arguments that may be used to customize the hole. These vary depending on the type of hole being created.

Return Value

This method returns a reference to the same Workplane object, allowing for method chaining.

Description

The hole method is used to create a cutout hole in a solid object. This method can be used to create simple circular holes, as well as more complex holes such as counterbores and countersinks.

If depth is not specified, the hole will be created through the entire solid object. If depth is specified, the hole will only be created to the specified depth.

The tolerance parameter is used to specify the maximum allowable deviation from the exact geometry of the hole. This can be particularly useful when working with complex geometries, as it allows for a certain amount of flexibility in the design without sacrificing accuracy.

The kind parameter allows for the creation of different types of holes. The "simple" option creates a simple circular hole, while the "counterbore" option creates a hole with a wider diameter at the top. The "countersink" option creates a hole with a wider diameter at the bottom.

Additional keyword arguments may be used to further customize the hole. These vary depending on the type of hole being created.

Examples

Creating a simple hole with a diameter of 5mm:

workplane = cq.Workplane('XY')
result = workplane.box(10, 10, 10).faces().workplane().hole(5)

Creating a counterbore hole with a diameter of 10mm and a counterbore diameter of 20mm:

workplane = cq.Workplane('XY')
result = workplane.box(10, 10, 10).faces().workplane().hole(
   diameter=10,
   kind="counterbore",
   cbore_diameter=20,
   cbore_depth=5,
)

Creating a countersink hole with a diameter of 5mm and a countersink angle of 90 degrees:

workplane = cq.Workplane('XY')
result = workplane.box(10, 10, 10).faces().workplane().hole(
   diameter=5,
   kind="countersink",
   angle=90,
   depth=3,
)

Notes

  • The hole method operates on a 2D plane, so it must be preceded by a call to the faces or edges method to select the face or edge of the solid to work on.
  • The units used for the diameter and depth parameters can be specified as a string, such as "5 mm" or "0.25 inch". If no units are specified, the default units for the current document will be used.