cadquery
Sketch
Workplane
Assembly

Sketch.parray()

The Sketch.parray() method is a part of the cadquery Python library which allows you to easily create complex 3D models by defining simple 2D sketches and extruding them into the third dimension.

Overview

Sketch.parray() is used to create arrays of parts within a sketch. It takes one or more parts, along with information about how those parts should be arranged, and creates a rectangular or polar array of those parts within the sketch.

Syntax

The syntax for Sketch.parray() is as follows:

def parray(self, qty, xSpacing=None, ySpacing=None, xOffset=None, yOffset=None, xDir=None, yDir=None):
  • qty: The number of parts to create in the array.
  • xSpacing: The amount of space between each part in the horizontal direction. If not specified, defaults to the width of the part.
  • ySpacing: The amount of space between each part in the vertical direction. If not specified, defaults to the height of the part.
  • xOffset: The distance to offset the array from the origin in the horizontal direction. If not specified, defaults to 0.
  • yOffset: The distance to offset the array from the origin in the vertical direction. If not specified, defaults to 0.
  • xDir: A 2D vector defining the direction of the horizontal axis. If not specified, defaults to [1, 0].
  • yDir: A 2D vector defining the direction of the vertical axis. If not specified, defaults to [0, 1].

Examples

Here are a few examples of how Sketch.parray() can be used:

# Create a rectangular array of 3 parts
part = cq.Workplane("XY").rect(1, 1).extrude(1)
sketch = cq.Workplane("XY").add(part).parray(3)

# Create a polar array of 6 parts
part = cq.Workplane("XY").rect(1, 1).extrude(1)
sketch = cq.Workplane("XY").add(part).polarArray(6, 10)

# Create a rectangular array with custom spacing and an offset
part = cq.Workplane("XY").rect(1, 1).extrude(1)
sketch = cq.Workplane("XY").add(part).parray(3, xSpacing=2, yOffset=2)

Conclusion

Sketch.parray() is a useful method for creating arrays of parts within a sketch in cadquery. It allows you to easily create complex patterns and arrangements of parts with just a few lines of code. Just remember to provide the necessary parameters for spacing, orientation, and quantity to achieve the desired result.