Unfold

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


class _Bracket(Part):
    """One L-bracket — folded, or unfolded to its flat pattern."""

    def __init__(self, flatten=False, width=60, depth=40, thickness=2, wall_height=20):
        s = Sketch(self.xy())
        base = SheetMetalBaseFlange(
            profile=Rectangle.from_center_and_sides(s.origin, width, depth), thickness=thickness
        )
        front = Line(Point(s, -width / 2, -depth / 2), Point(s, width / 2, -depth / 2))
        body = SheetMetalEdgeFlange(body=base, edge=front, length=wall_height)
        if flatten:
            body = Unfold(body=body)
        self.add_operation(SheetMetalToSolid(body=body))
        self.paint("orange" if flatten else "light_blue")


class SheetMetalUnfoldComparison(Assembly):
    """The same bracket twice: folded (left, blue) next to its unfolded flat
    pattern (right, orange)."""

    def __init__(self, separation=50):
        folded = _Bracket(flatten=False)
        folded.translate([-separation, 0, 0])
        self.add_component(folded)
        flat = _Bracket(flatten=True)
        flat.translate([separation, 0, 0])
        self.add_component(flat)


show(SheetMetalUnfoldComparison())

The Unfold node computes the flat pattern of a sheet-metal body — the shape it would have if every bend were flattened. The assembly above shows the same bracket twice: folded (left, blue) next to its unfolded flat pattern (right, orange), so you can see each 90° bend trade for a flat bend-allowance strip.

Each bend contributes its neutral-fibre arc length: (radius + k_factor * thickness) * angle. The result is itself a sheet-metal body, with bend lines preserved as marked edges, ready to feed into a DXF exporter.

Choose what stays put. By default the base flange stays where it is. Pass fixed_face= a plane lying on any flange’s face to flatten around that flange instead. Below, the bracket is flattened around its wall, so the flat pattern stands upright in the wall’s plane:

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,
    SheetMetalEdgeFlange,
    SheetMetalToSolid,
    Sketch,
    Unfold,
    show,
)


class _Bracket(Part):
    """An L-bracket, optionally flattened with its WALL held in place."""

    def __init__(self, flatten=False, width=60, depth=40, wall=20, thickness=2):
        s = Sketch(self.xy())
        body = SheetMetalBaseFlange(
            profile=Rectangle.from_center_and_sides(s.origin, width, depth),
            thickness=thickness,
        )
        front = Line(Point(s, -width / 2, -depth / 2), Point(s, width / 2, -depth / 2))
        body = SheetMetalEdgeFlange(body=body, edge=front, length=wall)
        if flatten:
            # The wall's outer face lies on the XZ plane shifted to y = -depth/2.
            wall_face = self.xz().get_parallel_plane(depth / 2)
            body = Unfold(body=body, fixed_face=wall_face)
        self.add_operation(SheetMetalToSolid(body=body))
        self.paint("orange" if flatten else "light_blue")


class UnfoldFixedFace(Assembly):
    """Unfold(fixed_face=…): the bracket (left) flattened around its wall
    instead of its base (right) — the flat pattern stands upright in the
    wall's plane."""

    def __init__(self):
        folded = _Bracket()
        folded.translate([-40, 0, 0])
        self.add_component(folded)
        flat = _Bracket(flatten=True)
        flat.translate([40, 0, 0])
        self.add_component(flat)


show(UnfoldFixedFace())
from cadbuildr.foundation import (
    Assembly,
    Line,
    Part,
    Point,
    Rectangle,
    SheetMetalBaseFlange,
    SheetMetalEdgeFlange,
    SheetMetalToSolid,
    Sketch,
    Unfold,
    show,
)


class _Bracket(Part):
    """An L-bracket, optionally flattened with its WALL held in place."""

    def __init__(self, flatten=False, width=60, depth=40, wall=20, thickness=2):
        s = Sketch(self.xy())
        body = SheetMetalBaseFlange(
            profile=Rectangle.from_center_and_sides(s.origin, width, depth),
            thickness=thickness,
        )
        front = Line(Point(s, -width / 2, -depth / 2), Point(s, width / 2, -depth / 2))
        body = SheetMetalEdgeFlange(body=body, edge=front, length=wall)
        if flatten:
            # The wall's outer face lies on the XZ plane shifted to y = -depth/2.
            wall_face = self.xz().get_parallel_plane(depth / 2)
            body = Unfold(body=body, fixed_face=wall_face)
        self.add_operation(SheetMetalToSolid(body=body))
        self.paint("orange" if flatten else "light_blue")


class UnfoldFixedFace(Assembly):
    """Unfold(fixed_face=…): the bracket (left) flattened around its wall
    instead of its base (right) — the flat pattern stands upright in the
    wall's plane."""

    def __init__(self):
        folded = _Bracket()
        folded.translate([-40, 0, 0])
        self.add_component(folded)
        flat = _Bracket(flatten=True)
        flat.translate([40, 0, 0])
        self.add_component(flat)


show(UnfoldFixedFace())

Refold. SheetMetalFold(body=Unfold(body=part)) hands back the folded body. Pass refold=[...] to fold only some bends back up; see Fold & partial refold.

Lofted bends. A SheetMetalLoftedBend transition (here a U-channel blending into a half-round) unfolds by triangulation, the classic layout method for hoppers and transitions:

  • both profiles are sampled at matching fractions of their length;
  • the sheet between them is split into thin triangles;
  • the triangles are laid flat edge to edge, each keeping its true side lengths.

The flat plate has the sheet’s true area:

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


class _Transition(Part):
    """The U-channel → half-round duct transition, folded or flattened."""

    def __init__(self, flatten, height=40, thickness=2):
        bottom = Sketch(self.xy())
        top = Sketch(self.xy().get_parallel_plane(height))
        u_channel = CustomOpenShape(
            [
                Line(Point(bottom, -20, 0), Point(bottom, -20, 20)),
                Line(Point(bottom, -20, 20), Point(bottom, 20, 20)),
                Line(Point(bottom, 20, 20), Point(bottom, 20, 0)),
            ]
        )
        half_round = CustomOpenShape(
            [Arc(Point(top, -15, 0), Point(top, 0, 15), Point(top, 15, 0))]
        )
        body = SheetMetalLoftedBend(
            profile_start=u_channel, profile_end=half_round, thickness=thickness
        )
        if flatten:
            body = Unfold(body=body)
        self.add_operation(SheetMetalToSolid(body=body))
        self.paint("dark_orange" if flatten else "light_blue")


class LoftedUnfold(Assembly):
    """A lofted bend (left) and its flat pattern (right).

    The transition is built as a developable sheet: each straight side of the
    channel fans to the one point of the half-round with a parallel tangent
    (a flat triangle) and each corner fans over a quarter of the half-round
    (a cone). Unfold lays those rulings flat with their true lengths at the
    K-factor neutral surface, on the start profile's plane. Profiles that no
    smooth developable sheet can join (e.g. twisted against each other) are
    refused by Unfold with the reason."""

    def __init__(self):
        folded = _Transition(flatten=False)
        folded.translate([-60, 0, 0])
        self.add_component(folded)
        flat = _Transition(flatten=True)
        flat.translate([40, 0, 0])
        self.add_component(flat)


show(LoftedUnfold())
from cadbuildr.foundation import (
    Arc,
    Assembly,
    CustomOpenShape,
    Line,
    Part,
    Point,
    SheetMetalLoftedBend,
    SheetMetalToSolid,
    Sketch,
    Unfold,
    show,
)


class _Transition(Part):
    """The U-channel → half-round duct transition, folded or flattened."""

    def __init__(self, flatten, height=40, thickness=2):
        bottom = Sketch(self.xy())
        top = Sketch(self.xy().get_parallel_plane(height))
        u_channel = CustomOpenShape(
            [
                Line(Point(bottom, -20, 0), Point(bottom, -20, 20)),
                Line(Point(bottom, -20, 20), Point(bottom, 20, 20)),
                Line(Point(bottom, 20, 20), Point(bottom, 20, 0)),
            ]
        )
        half_round = CustomOpenShape(
            [Arc(Point(top, -15, 0), Point(top, 0, 15), Point(top, 15, 0))]
        )
        body = SheetMetalLoftedBend(
            profile_start=u_channel, profile_end=half_round, thickness=thickness
        )
        if flatten:
            body = Unfold(body=body)
        self.add_operation(SheetMetalToSolid(body=body))
        self.paint("dark_orange" if flatten else "light_blue")


class LoftedUnfold(Assembly):
    """A lofted bend (left) and its flat pattern (right).

    The transition is built as a developable sheet: each straight side of the
    channel fans to the one point of the half-round with a parallel tangent
    (a flat triangle) and each corner fans over a quarter of the half-round
    (a cone). Unfold lays those rulings flat with their true lengths at the
    K-factor neutral surface, on the start profile's plane. Profiles that no
    smooth developable sheet can join (e.g. twisted against each other) are
    refused by Unfold with the reason."""

    def __init__(self):
        folded = _Transition(flatten=False)
        folded.translate([-60, 0, 0])
        self.add_component(folded)
        flat = _Transition(flatten=True)
        flat.translate([40, 0, 0])
        self.add_component(flat)


show(LoftedUnfold())

DXF. Unfold and then SheetMetalToSolid give a flat body that the viewer’s DXF button exports. Every flange outline and every cut-out (holes, slots, corner reliefs, extruded-hole pre-forms) goes on the OUTLINE layer, and bend lines go on BEND_UP / BEND_DOWN.

from cadbuildr.foundation import Part, Assembly, Sketch, Rectangle, Line, Point, show
from cadbuildr.foundation import SheetMetalBaseFlange, SheetMetalEdgeFlange, Unfold, SheetMetalToSolid


class _Bracket(Part):
    """One L-bracket — folded, or unfolded to its flat pattern."""

    def __init__(self, flatten=False, width=60, depth=40, thickness=2, wall_height=20):
        s = Sketch(self.xy())
        base = SheetMetalBaseFlange(
            profile=Rectangle.from_center_and_sides(s.origin, width, depth), thickness=thickness
        )
        front = Line(Point(s, -width / 2, -depth / 2), Point(s, width / 2, -depth / 2))
        body = SheetMetalEdgeFlange(body=base, edge=front, length=wall_height)
        if flatten:
            body = Unfold(body=body)
        self.add_operation(SheetMetalToSolid(body=body))
        self.paint("orange" if flatten else "light_blue")


class SheetMetalUnfoldComparison(Assembly):
    """The same bracket twice: folded (left, blue) next to its unfolded flat
    pattern (right, orange)."""

    def __init__(self, separation=50):
        folded = _Bracket(flatten=False)
        folded.translate([-separation, 0, 0])
        self.add_component(folded)
        flat = _Bracket(flatten=True)
        flat.translate([separation, 0, 0])
        self.add_component(flat)


show(SheetMetalUnfoldComparison())