FoundationPartsSheet MetalConvert from Solid

Convert from Solid

SheetMetalFromSolid(solid, thickness, base_face) turns an ordinary solid into sheet metal. That’s handy when it’s easier to model the outside of an enclosure first.

  • The face picked by base_face (a FaceFinder) becomes the base flange, with the material thickness inside the solid.
  • Every planar side face that meets the base face at a right angle becomes a wall bent up from that edge. The wall’s outer face lies on the side face and it ends at the solid’s height.
  • Faces that don’t touch the base face, such as the box’s top, are left open.
  • Corners are ripped: walls stop short of each corner by rip_gap / 2 plus the bend zone, so neighbouring walls never collide and the body unfolds (right, orange).
from cadbuildr.foundation import (
    Assembly,
    Extrusion,
    FaceFinder,
    InPlaneFinderRule,
    Part,
    Rectangle,
    SheetMetalFromSolid,
    SheetMetalToSolid,
    Sketch,
    Unfold,
    show,
)


class _ConvertedBox(Part):
    """Model the enclosure as a plain solid, then convert it to sheet metal:
    the bottom face becomes the base, the four sides become walls, the top
    stays open and the corners are ripped."""

    def __init__(self, flatten=False, length=60, width=40, height=25, thickness=1.5):
        s = Sketch(self.xy())
        block = Extrusion(
            Rectangle.from_center_and_sides(s.origin, length, width), height
        )
        bottom = FaceFinder(rule=InPlaneFinderRule(self.xy(), 0))
        body = SheetMetalFromSolid(solid=block, thickness=thickness, base_face=bottom)
        if flatten:
            body = Unfold(body=body)
        self.add_operation(SheetMetalToSolid(body=body))
        self.paint("orange" if flatten else "light_blue")


class SheetMetalFromSolidBox(Assembly):
    """SheetMetalFromSolid: the converted box (left) and its flat pattern (right)."""

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


show(SheetMetalFromSolidBox())