FoundationPartsOperationsEmboss & Wrap

Emboss & Wrap

Both operations put a 2D profile onto a curved face, then add material there (mode=EmbossMode.RAISE, the default) or cut it in (EmbossMode.ENGRAVE) by depth. Pick the face with a FaceFinder.

Emboss(solid, profile, face, depth) projects the profile straight along its sketch normal, like a shadow. Draw it on any plane facing the face: the star (blue bar) is drawn on a plane above the bar and raised 1 mm onto its round top. The slot (green bar) is engraved 0.8 mm the same way. A projection stretches the profile where the face slopes away from the sketch.

Wrap(solid, profile, face, depth) rolls the profile around a cylindrical face instead, so lengths are kept. The sketch’s x axis runs around the cylinder (x = arc length) and its y axis along it. Draw the profile on a plane tangent to the cylinder, with the sketch origin on the surface, e.g. self.xz().get_parallel_plane(radius) for the front of an upright can.

On the orange can, a 50 × 12 label recess is wrapped 0.6 mm deep, and its 50 mm really runs 50 mm around the circumference. Then Text is wrapped onto the recess floor and raised 0.6 mm, so the lettering ends flush with the can.

Keep a wrapped profile within one face: an extruded circle’s side is two half-cylinder faces, so a label can span up to half the circumference.

import math

from cadbuildr.foundation import *


def _star(sketch, outer=8, inner_ratio=0.45, points=5):
    """A star polygon centred on the sketch origin."""
    corners = []
    for i in range(2 * points):
        r = outer if i % 2 == 0 else outer * inner_ratio
        a = math.pi / 2 + i * math.pi / points
        corners.append(Point(sketch, r * math.cos(a), r * math.sin(a)))
    return Polygon([Line(p, q) for p, q in zip(corners, corners[1:] + corners[:1])])


def _round_bar(part, radius, length):
    """A bar of `radius` lying along X, centred on the origin."""
    side = Sketch(part.yz())
    return Extrusion(Circle(side.origin, radius), length / 2, -length / 2)


class EmbossedHandle(Part):
    """Emboss: a star raised 1 mm onto the curved top of a round bar. The star
    is drawn flat on a plane above the bar and projected straight down onto
    the cylindrical face, so it follows the curvature."""

    def __init__(self, radius=12, length=60):
        bar = _round_bar(self, radius, length)
        above = Sketch(self.xy().get_parallel_plane(radius + 5))
        curved_top = FaceFinder(rule=ContainsPointFinderRule(Point3D(0, 0, radius)))
        self.add_operation(Emboss(bar, _star(above), curved_top, 1.0))
        self.translate([0, -45, 0])
        self.paint("light_blue")


class EngravedHandle(Part):
    """Emboss(mode=ENGRAVE): the same projection, cut 0.8 mm into the bar."""

    def __init__(self, radius=12, length=60):
        bar = _round_bar(self, radius, length)
        above = Sketch(self.xy().get_parallel_plane(radius + 5))
        slot = SlotCenterToCenter(Point(above, -15, 0), Point(above, 15, 0), 5)
        curved_top = FaceFinder(rule=ContainsPointFinderRule(Point3D(0, 0, radius)))
        self.add_operation(Emboss(bar, slot, curved_top, 0.8, mode=EmbossMode.ENGRAVE))
        self.paint("light_green")


class WrappedLabel(Part):
    """Wrap: a 50 × 8 band rolled 0.6 mm into a Ø40 can (it keeps its true
    50 mm length around the circumference), and lettering wrapped above it,
    raised 0.8 mm."""

    def __init__(self, radius=20, height=40):
        base = Sketch(self.xy())
        can = Extrusion(Circle(base.origin, radius), height)
        # The XZ plane pushed to y = -radius touches the front of the can:
        # sketch x runs around the can, sketch y up it.
        front = Sketch(self.xz().get_parallel_plane(radius))
        front_face = FaceFinder(rule=ContainsPointFinderRule(Point3D(0, -radius, height / 2)))
        band = Rectangle.from_center_and_sides(Point(front, 0, 10), 50, 8)
        can = Wrap(can, band, front_face, 0.6, mode=EmbossMode.ENGRAVE)
        label = Text(front, "CADBUILDR", 7, xshift=-19, yshift=24)
        self.add_operation(Wrap(can, label, front_face, 0.8))
        self.translate([0, 50, 0])
        self.paint("dark_orange")


class EmbossWrapExamples(Assembly):
    def __init__(self):
        self.add_component(EmbossedHandle())
        self.add_component(EngravedHandle())
        self.add_component(WrappedLabel())


show(EmbossWrapExamples())