Skip to content

Instantly share code, notes, and snippets.

@medicationforall
Last active October 6, 2023 20:51
Show Gist options
  • Save medicationforall/2b013ac29875a120fb9626eb24b5408a to your computer and use it in GitHub Desktop.
Save medicationforall/2b013ac29875a120fb9626eb24b5408a to your computer and use it in GitHub Desktop.

CadQuery Array Operations


pArray

Workplane.polarArray

result = (
    cq.Workplane("XY")
    .polarArray(
        radius = 20, 
        startAngle = 0, 
        angle = 90, 
        count = 20,
        fill = True,
        rotate = True
    )
    .box(1,1,1)
)

02_parray_01

rarray

Workplane.rarray

result = (
    cq.Workplane("XY")
    .rarray(
        xSpacing = 10, 
        ySpacing = 10,
        xCount = 5, 
        yCount= 5, 
        center = True)
    .box(1,1,1)
)

rarray_01


eachpoint example

Workplane.eachpoint

import cadquery as cq
from cadqueryhelper import shape

def add_star(loc):
    return shape.star().val().located(loc)
    
star_arc =(
    cq.Workplane("XY")
    .polarArray(
        radius  =150, 
        startAngle  = 0, 
        angle  = 90, 
        count  = 15,
        fill = True,
        rotate = True
    )
    .eachpoint(callback = add_star)
)

03_parray_stars

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment