Open
Description
Sample code
import cadquery as cq
space = 19.05
cherryCutOutSize=14.05
cherrySize=14.58
cols = 2
rows = 4
width = cols * space
depth = rows * space
lip=3
height = 10
plateThickness=3
bottom = (cq.Workplane("XY")
.box(width,depth,height)
.faces("+Z")
.shell(lip)
.faces(">Z")
.wires(cq.selectors.AreaNthSelector(-1))
.toPending()
.workplane()
.extrude(1)
.faces(">Z")
.wires()
.item(0)
.toPending()
.workplane()
.offset2D(-lip/2)
.cutBlind(-plateThickness)
)
cherryCut = (cq.Workplane()
.box(cherryCutOutSize, cherryCutOutSize, plateThickness+2)
# Side cuts
.faces(">Z")
.edges("|Y")
.rect(1,4)
.cutThruAll()
# Potrusions
.faces(">Y or <Y")
.edges("<Z")
.rect(4,1)
.extrude(plateThickness+1)
# Add chamfer to potrusions
.faces(">Y or <Y")
.edges(">Z")
.chamfer(0.2,0.4)
)
plate = (cq.Workplane("XY")
.box(width,depth,plateThickness)
.faces(">Z")
.workplane()
.rarray(space,space,cols,rows,True)
.cutEach(lambda loc: cherryCut.val().moved(loc).translate((0,0,-2)))
)
top = (cq.Workplane("XY")
.box(width,depth,height/2)
.faces("-Z")
.shell(lip)
.faces(">Z")
.rect(width-lip,depth-lip)
.cutThruAll()
.faces("<Z")
.wires(cq.selectors.AreaNthSelector(-1))
.toPending()
.workplane()
.extrude(1)
.faces("<Z")
.wires()
.item(0)
.toPending()
.workplane()
.offset2D(-lip/2)
.cutBlind(-plateThickness)
)
cherry = cq.Workplane("XY").box(15.6,15.6,3.6+11.6+3.3)
switches = (cq.Workplane()
.rect(width,depth, forConstruction=True)
.rarray(space,space,cols,rows,True)
.eachpoint(lambda loc: cherry.val().moved(loc))
.combine(glue=True)
)
dsa1u = cq.Workplane("XY").box(15.6,15.6,10)
caps = (cq.Workplane()
.rect(width,depth, forConstruction=True)
.rarray(space,space,cols,rows,True)
.eachpoint(lambda loc: dsa1u.val().moved(loc))
.combine(glue=True)
)
keyboard = (cq.Assembly()
.add(bottom, name="bottom", color=cq.Color(0, 0, 1, 1))
.add(plate, name="plate", color=cq.Color(1,1,0,1))
.add(switches, name="switches", color=cq.Color(0,1,0,1))
.add(caps, name="caps", color=cq.Color(1,0,1,1))
.add(top, name="top", color=cq.Color(0,1,1,1))
)
switches.faces("<X").edges(">Y").vertices(">Z").tag("refpoint")
bottom.faces("<X[-4]").tag("xface")
bottom.faces(">Y[-4]").tag("yface")
(keyboard
.constrain("bottom@faces@>Z", "plate@faces@<Z", "PointInPlane", param=-1.5)
.constrain("plate@faces@>Z", "switches@faces@<Z", "PointInPlane", param=-7.7)
.constrain("switches@faces@>Z", "caps@faces@<Z", "PointInPlane", param=-3)
.constrain("plate@faces@>Z", "top@faces@<Z", "PointInPlane", param=-1.5)
.constrain("plate@faces@<X", "bottom@faces@<X", "Axis")
.constrain("plate@faces@<Y", "bottom@faces@<Y", "Axis")
.constrain("plate@faces@<X", "switches@faces@<X", "Axis")
.constrain("plate@faces@<Y", "switches@faces@<Y", "Axis")
.constrain("plate@faces@<X", "top@faces@<X", "Axis")
.constrain("plate@faces@<Y", "top@faces@<Y", "Axis")
.constrain("plate@faces@<X", "caps@faces@<X", "Axis")
.constrain("plate@faces@<Y", "caps@faces@<Y", "Axis")
)
keyboard.solve()
print(keyboard.toCompound().isValid())
kwp = cq.Workplane(keyboard.toCompound())
half = (kwp
.faces("<Z")
.workplane()
.hole(20)
)
half2 = (kwp
.faces("<Z")
.workplane()
.rect(20,20)
.cutThruAll()
.translate((80,0,0))
)
cutBox = cq.Workplane("XY").box(20,200,50)
half3 = (kwp
.faces("<Z")
.workplane()
.cut(cutBox)
.translate((-80,0,0))
)
half4 = (kwp
.faces("<Y")
.workplane(offset=-30)
.split(keepTop=True)
.translate((0,-100,0))
)
show_object(half)
show_object(half2)
show_object(half3)
show_object(half4)
debug(cutBox.translate((-80,0,0)))
Running this code should give this result
Neither of which is expected. It seems like cq is unable to properly split or cut compounds here. I would expect split
to work just like on any other solid. Giving me the the split object, not this result. And I would expect cut
and cutThruAll
to cut thru the entire piece, not just some layers of it.