cadquery icon indicating copy to clipboard operation
cadquery copied to clipboard

Length of Sketch.slot() incorrect

Open gumyr opened this issue 3 years ago • 5 comments

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})

slot_bug

gumyr avatar Apr 06 '22 14:04 gumyr

I had assumed the new slot implementation was by design.

lorenzncode avatar Apr 07 '22 03:04 lorenzncode

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.

gumyr avatar Apr 07 '22 13:04 gumyr

If you do milling, it is quite intuitive.

adam-urbanczyk avatar Apr 07 '22 17:04 adam-urbanczyk

In Fusion360 there are several different types of slots, as follows: Fusion360Slot 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)?

gumyr avatar Apr 07 '22 18:04 gumyr

A potential solution would be to have some key word arguments (instead of w) like:

  • overallWidth: float
  • centerToCenter: 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.

gumyr avatar Apr 07 '22 19:04 gumyr