cadquery
Sketch
Workplane
Assembly

Workplane.slot2D()

The slot2D() method creates a 2D slot or groove in the workplane starting at the current position of the workplane.

Syntax

slot2D(width, depth, direction='X', centered=True)

Parameters

  • width (float): The width of the slot or groove.
  • depth (float): The depth of the slot or groove.
  • direction (str, optional): The direction of the slot or groove. Valid values are 'X', 'Y', and 'Z'. Defaults to 'X'.
  • centered (bool, optional): If True, the slot or groove will be centered on the current position of the workplane. If False, the slot or groove will be offset to one side. Defaults to True.

Returns

A cadquery.Workplane object representing the modified workplane.

Example

import cadquery as cq

# Create a simple box
box = cq.Workplane('XY').box(10, 10, 10)

# Create a slot in the X direction
slot = box.faces('+X').workplane().slot2D(2, 5)

# Create a slot in the Y direction, offset from the center
slot2 = box.faces('-Y').workplane().slot2D(2, 5, direction='Y', centered=False)

# Show the result
show_object(slot)
show_object(slot2)

In this example, we start with a simple box and create two slots: one in the X direction and one in the Y direction. The first slot is centered on the workplane, while the second slot is offset to one side. The resulting objects are then displayed using the show_object() function.

Notes

  • The slot2D() method can be used to create slots or grooves in any direction, as long as it is parallel to one of the workplane axes ('X', 'Y', or 'Z').
  • The centered parameter can be used to create slots or grooves that are centered on the current position of the workplane or offset to one side. This is useful when creating slots or grooves that need to be symmetric.
  • The slot2D() method removes material from the workplane, creating a void in the resulting object. To create a solid object with a slot or groove, you will need to use the cut() method to subtract the void from another object.