cadquery
cadquery copied to clipboard
Length of Sketch.slot() incorrect
The Sketch.slot() method produces a slot with the incorrect length (w+h). Here is an illustration of how it doesn't agree with the Workplane.slot2D() and the fixed code:
from typing import Literal, Optional
import cadquery as cq
from cadquery import Vector, Edge, Wire
from cadquery.sketch import Real, Modes
from cadquery.cq import T
def _fixed_slot(
self: T,
w: Real,
h: Real,
angle: Real = 0,
mode: Modes = "a",
tag: Optional[str] = None,
) -> T:
"""
Construct a slot-shaped face.
"""
p1 = Vector(-w / 2 + h / 2, h / 2)
p2 = Vector(w / 2 - h / 2, h / 2)
p3 = Vector(-w / 2 + h / 2, -h / 2)
p4 = Vector(w / 2 - h / 2, -h / 2)
p5 = Vector(-w / 2, 0)
p6 = Vector(w / 2, 0)
e1 = Edge.makeLine(p1, p2)
e2 = Edge.makeThreePointArc(p2, p6, p4)
e3 = Edge.makeLine(p4, p3)
e4 = Edge.makeThreePointArc(p3, p5, p1)
wire = Wire.assembleEdges((e1, e2, e3, e4))
return self.face(wire, angle, mode, tag)
cq.Sketch.fixed_slot = _fixed_slot
workplane_slot = cq.Workplane("XZ").slot2D(10, 5)
workplane_rect = cq.Workplane("XZ").rect(10, 5)
sketch_slot = cq.Sketch().slot(10, 5)
sketch_fixed_slot = cq.Sketch().fixed_slot(10, 5)
sketch_rect = cq.Sketch().rect(10, 5)
if "show_object" in locals():
show_object(workplane_slot, name="workplane_slot")
show_object(workplane_rect, name="workplane_rect")
show_object(sketch_slot, name="sketch_slot", options={"color": "blue"})
show_object(sketch_fixed_slot, name="sketch_fixed_slot", options={"color": "red"})
show_object(sketch_rect, name="sketch_rect", options={"alpha": 0.5})

I had assumed the new slot implementation was by design.
If so it's non-intuitive in that no part of the slot has dimension w and it doesn't match the Workplane.slot2D() nor either rect() method. I only noticed the problem after a 5 hour 3D print where the slotted hole in my design was too large. It really should be fixed.
If you do milling, it is quite intuitive.
In Fusion360 there are several different types of slots, as follows:
The problem I'm trying to raise is not that Sketch.slot is somehow invalid but it's now a "Center to Center Slot" while Workplane.slot2D is an "Overall Slot". Why introduce this confusion - especially when it's easy to use both type of slots in the same design (I did in the part I printed with oversized Sketch slots)?
A potential solution would be to have some key word arguments (instead of w) like:
overallWidth: floatcenterToCenter: float
then it would be clear to the user what type of slot they are creating. One could expand this interface to include list of points for the other types of slots.