Hole variants

Renders the 3D model in your browser. The first run downloads the Python runtime (≈30 MB).
import math

from cadbuildr.foundation import *
from cadbuildr.foundation import Thread, Point3D


class HolesPlate(Part):
    """Four hole variants drilled into a plate, then sectioned to reveal each bore.

    `Hole` is the plain cylindrical bore. `CounterBoreHole` adds a stepped, flat
    recess so a socket-head-cap-screw head sits flush. `CounterSinkHole` adds a
    conical chamfer for a flat-head screw. `TappedHole` is sized at
    radius = thread_size / 2 — the bore for an M-series thread; a real helical
    `Thread` is swept into its wall here so it reads as tapped.

    All four are drilled **along the sketch normal**: the wide opening sits on
    the entry face and the bore narrows into the material. The holes are placed
    on the plate's top face, so a final `Box` cut that removes the front half
    (y > 0) slices straight through every bore axis, exposing the profile of
    each variant side by side for inspection.
    """

    def __init__(self):
        thickness = 16.0
        depth = 12.0
        s = Sketch(self.xy())
        # Flat plate, centered on the origin, `thickness` tall along Z.
        self.add_operation(Box(s.origin, w=90, d=30, h=thickness))

        # Drill from the TOP face: take the top surface plane and flip its
        # normal to point down into the plate (rotate 180° about its X axis), so
        # the holes bore downward with the wide openings on the top surface.
        face = Sketch(
            self.xy()
            .get_parallel_plane(thickness / 2.0)
            .get_angle_plane_from_axis([1.0, 0.0, 0.0], math.pi)
        )
        self.add_operation(Hole(Point(face, -33, 0), radius=2.5, depth=depth))
        self.add_operation(
            CounterBoreHole(Point(face, -11, 0), radius=2.5, depth=depth,
                            cbore_radius=5, cbore_depth=5),
        )
        self.add_operation(
            CounterSinkHole(Point(face, 11, 0), radius=2.5, depth=depth,
                            csink_radius=5, csink_angle_deg=90),
        )
        # Tapped hole: clearance bore + a real swept thread on its wall. A
        # `Thread` is a helical Sweep — accurate but compute-heavy — so it is an
        # explicit, opt-in operation rather than baked into every `TappedHole`.
        thread_size = 6.0
        self.add_operation(
            TappedHole(point=Point(face, 33, 0), thread_size=thread_size, depth=depth),
        )
        top_z = thickness / 2.0
        sx = Sketch(self.xz())
        self.add_operation(Thread(
            profile=Circle(sx.origin, 0.45),
            pitch=1.0,
            height=depth - 1.5,
            radius=thread_size / 2.0,
            center=Point3D(33.0, 0.0, top_z - depth + 1.0),
            dir=Point3D(0.0, 0.0, 1.0),
        ))

        # Section cut: remove the y > 0 half to expose the bores in cross-section.
        self.add_operation(
            Box(Point(s, 0, 20), w=120, d=40, h=4 * thickness,
                cut=BoolParameter(value=True)),
        )
        self.paint("light_bluish_gray")


show(HolesPlate())

Four hole variants share the same anchor convention: pass a sketch Point (typically a translated Sketch.origin) and the depth is measured along the sketch normal.

Hole(point, radius, depth)
CounterBoreHole(point, radius, depth, cbore_radius, cbore_depth)
CounterSinkHole(point, radius, depth, csink_radius, csink_angle_deg)
TappedHole(point, thread_size, depth)        # bore at radius = thread_size / 2

CounterBoreHole and CounterSinkHole desugar to a Lathe of a stepped profile with cut=true, so the bore and the recess come out as a single subtraction. TappedHole itself is just the clearance bore; the example sweeps a real helical Thread into its wall so it reads as tapped. Threads are a helical Sweep — accurate but compute-heavy — so add one explicitly only where you need the actual thread rendered.