cadquery
Sketch
Workplane
Assembly

Workplane.close()

The close() method in Workplane class is used to create a straight, closed wire by drawing a 2D or 3D path that starts and ends at the same point. This method is particularly useful for creating shapes that need to be extruded or revolved, such as rings, discs, or cylinders.

Syntax

close(inplace=True)
  • inplace (optional): A boolean value that indicates whether the original object should be modified in place or a new object should be returned. The default value is True.

Parameters

This method does not accept any parameters.

Return Value

If inplace is True (default), this method returns the modified Workplane object. If inplace is False, it returns a new Workplane object that contains the closed wire.

Example

import cadquery as cq

# Create a rectangle with rounded corners
rect = cq.Workplane("XY").rect(10, 5).roundCorner(1)

# Close the wire to create a ring
ring = rect.close()

# Extrude the ring to create a cylinder
cyl = ring.extrude(10)

In this example, we create a rectangle with rounded corners using rect() and roundCorner() methods in Workplane. We then use the close() method to create a closed wire that is shaped like a ring. Finally, we extrude the ring using extrude() method to create a cylinder.

Notes

  • The close() method can only be used after creating a path with moveTo() and lineTo() methods. If there is no path defined, this method will raise an exception.

  • The close() method can be invoked multiple times on the same object. In each call, a new closed wire is created based on the existing path.

  • The close() method can also be used with extrude() and revolve() methods to create solid objects.

  • If inplace is False, the original Workplane object will not be modified. This can be useful for creating multiple closed wires based on the same path.