Miter Flange

Renders the 3D model in your browser. The first run downloads the Python runtime (≈30 MB).
from cadbuildr.foundation import (
    Assembly,
    Line,
    Part,
    Point,
    Rectangle,
    SheetMetalBaseFlange,
    SheetMetalMiterFlange,
    SheetMetalToSolid,
    Sketch,
    Unfold,
    show,
)
from cadbuildr.foundation.draw import Draw


class _Tray(Part):
    """A tray: one miter flange swept around all four base edges.

    The edges are listed head-to-tail (counter-clockwise), so neighbouring walls
    meet in true 45° miters. The section is a wall with an outward lip, drawn in
    (outward, up) coordinates.
    """

    def __init__(self, flatten=False, width=60, depth=40, wall=15, lip=6, thickness=2):
        s = Sketch(self.xy())
        body = SheetMetalBaseFlange(
            profile=Rectangle.from_center_and_sides(s.origin, width, depth),
            thickness=thickness,
        )
        d = Draw(Sketch(self.yz()))
        d.move_to(0.0, -thickness)
        d.line_to(thickness, -thickness)
        d.line_to(thickness, wall - thickness)
        d.line_to(thickness + lip, wall - thickness)
        d.line_to(thickness + lip, wall)
        d.line_to(0.0, wall)
        section = d.close()
        w, h = width / 2, depth / 2
        corners = [(-w, -h), (w, -h), (w, h), (-w, h)]
        edges = [
            Line(Point(s, *corners[i]), Point(s, *corners[(i + 1) % 4]))
            for i in range(4)
        ]
        body = SheetMetalMiterFlange(body=body, edges=edges, profile=section)
        if flatten:
            body = Unfold(body=body)
        self.add_operation(SheetMetalToSolid(body=body))
        self.paint("orange" if flatten else "light_blue")


class SheetMetalMiterTray(Assembly):
    """Miter flange around a closed loop of edges: folded (left) and flat (right)."""

    def __init__(self):
        folded = _Tray()
        folded.translate([-45, 0, 0])
        self.add_component(folded)
        flat = _Tray(flatten=True)
        flat.translate([55, 0, 0])
        self.add_component(flat)


show(SheetMetalMiterTray())

SheetMetalMiterFlange(body, edges, profile) sweeps a cross-section you draw yourself, in (outward, up) coordinates on a plane at right angles to the edge, along one edge or a chain of edges.

  • Miters. List the edges head-to-tail (here counter-clockwise around the base). Where two edges share an endpoint, the walls meet in a true miter on the corner’s bisector plane, with no overlap and no gap. The tray above sweeps one wall-with-lip section around all four edges.
  • flange_position shifts the section outward: MATERIAL_INSIDE (default) keeps it on the edge, MATERIAL_OUTSIDE moves it one thickness out, and BEND_OUTSIDE moves it thickness + bend radius out.
  • gap, start_offset, end_offset pull the free (un-mitred) ends back.
  • Flat pattern. Each edge records a bend to a wall as tall as the section, so Unfold lays the walls out around the base (right, orange).
from cadbuildr.foundation import (
    Assembly,
    Line,
    Part,
    Point,
    Rectangle,
    SheetMetalBaseFlange,
    SheetMetalMiterFlange,
    SheetMetalToSolid,
    Sketch,
    Unfold,
    show,
)
from cadbuildr.foundation.draw import Draw


class _Tray(Part):
    """A tray: one miter flange swept around all four base edges.

    The edges are listed head-to-tail (counter-clockwise), so neighbouring walls
    meet in true 45° miters. The section is a wall with an outward lip, drawn in
    (outward, up) coordinates.
    """

    def __init__(self, flatten=False, width=60, depth=40, wall=15, lip=6, thickness=2):
        s = Sketch(self.xy())
        body = SheetMetalBaseFlange(
            profile=Rectangle.from_center_and_sides(s.origin, width, depth),
            thickness=thickness,
        )
        d = Draw(Sketch(self.yz()))
        d.move_to(0.0, -thickness)
        d.line_to(thickness, -thickness)
        d.line_to(thickness, wall - thickness)
        d.line_to(thickness + lip, wall - thickness)
        d.line_to(thickness + lip, wall)
        d.line_to(0.0, wall)
        section = d.close()
        w, h = width / 2, depth / 2
        corners = [(-w, -h), (w, -h), (w, h), (-w, h)]
        edges = [
            Line(Point(s, *corners[i]), Point(s, *corners[(i + 1) % 4]))
            for i in range(4)
        ]
        body = SheetMetalMiterFlange(body=body, edges=edges, profile=section)
        if flatten:
            body = Unfold(body=body)
        self.add_operation(SheetMetalToSolid(body=body))
        self.paint("orange" if flatten else "light_blue")


class SheetMetalMiterTray(Assembly):
    """Miter flange around a closed loop of edges: folded (left) and flat (right)."""

    def __init__(self):
        folded = _Tray()
        folded.translate([-45, 0, 0])
        self.add_component(folded)
        flat = _Tray(flatten=True)
        flat.translate([55, 0, 0])
        self.add_component(flat)


show(SheetMetalMiterTray())