The center()
method is used in cadquery
to move the workplane to the center of the current bounding box of the solid or face on the current workplane.
The syntax for using the center()
method is:
center(offset=(0, 0, 0))
The center()
method accepts following parameters:
offset
(optional): A tuple of three float values representing the offset from the center to move the workplane to. Default value is (0, 0, 0)
.The center()
method does not return any value. It just moves the workplane to the center of the current bounding box.
import cadquery as cq
# Create a simple box
box = cq.Workplane().box(1, 1, 1)
# Move the workplane to the center of the box
box.faces(">Z").workplane().center()
# Add a hole at the center of the top face
box.faces(">Z").workplane().hole(0.1)
# Display the result
show_object(box)
Here's what the resulting object would look like using show_object
:
In the example above, we first create a simple box using the box()
method on a Workplane
object. Then, we move the workplane to the top face of the box using the faces()
method with a direction specifier of >Z
. Next, we move the workplane to the center of the face using the center()
method. Finally, we add a hole to the face using the hole()
method and display the resulting object using show_object()
.