cadquery icon indicating copy to clipboard operation
cadquery copied to clipboard

Irregular pocket using custom array on workplane

Open GaN-T opened this issue 4 months ago • 1 comments

I want to make an array of cavities using an irregular cutting shape on a custom list of points pushed onto a workplane face.

import cadquery as cq
import numpy as np

l = w= 9  # box dimensions
h = 2 # box height
t = -0.25 # cavity depth

cavityCenters = [
cq.Vector(2.5060005000000003, 3.0050005, 0.0),
cq.Vector(2.0060005000000003, 3.0040005, 0.0),
cq.Vector(1.5060005, 3.0030005, 0.0),
cq.Vector(1.0060005, 3.0020005000000003, 0.0),
cq.Vector(0.5060005, 3.0010005, 0.0),
cq.Vector(0.006000500000000016, 3.0000005, 0.0),
cq.Vector(-0.49399950000000004, 2.9990005, 0.0)
]


# shape of a single cavity

cavityShapePts = [np.array([-0.1353255,  0.1040445]),
np.array([-0.1809155,  0.0588155]),
np.array([-0.1652075,  0.0120525]),
 np.array([-0.1610545, -0.0522245]),
 np.array([-0.1136595, -0.1563145]),
 np.array([-0.0685205, -0.1437665]),
 np.array([-0.0194095, -0.1965785]),
 np.array([ 0.1208815, -0.1687735]),
 np.array([ 0.1193465, -0.1086485]),
 np.array([ 0.1954505, -0.0634195]),
 np.array([ 0.1605135, -0.0176485]),
 np.array([0.1754085, 0.0570105]),
 np.array([0.1182625, 0.1627245]),
 np.array([0.0731245, 0.1351905]),
 np.array([0.0257285, 0.1920655]),
 np.array([-0.0634655,  0.1675095]),
 np.array([-0.0824235,  0.1134335])]

box = cq.Workplane("XY").box(l,w,h).translate([0,0,-h/2])
box.faces(">Z").workplane().pushPoints(cavityCenters).polyline(cavityShapePts).close().cutBlind(t)

However, this only creates one cavity in the center, not the result I wanted. Any suggestion on how to create polylines on all the target points to do the cut together? Many thanks!

GaN-T avatar Jun 16 '25 09:06 GaN-T