FoundationPartsOperationsComposing operations

Composing operations

Solid operations feed into each other. Fillet, Chamfer, Shell, Draft, Mirror, Scale, Split and BooleanOperation accept any solid operation as input, including the result of another modifier.

Here Shell(Fillet(Extrusion)) rounds the four upright edges of a block, then hollows it into a 2 mm open-top enclosure. Add only the outermost operation to the part.

from cadbuildr.foundation import *
from cadbuildr.foundation.gen.models import ParallelToAxisRule


class RoundedEnclosure(Part):
    """Operations feed into each other: Shell(Fillet(Extrusion)).

    Round the four upright edges of a block, then hollow the rounded block
    into a 2 mm open-top enclosure. Before operations were composable, Shell
    could only take a raw Extrusion.
    """

    def __init__(self, length=60, width=40, height=25, corner_r=6, wall=2):
        s = Sketch(self.xy())
        block = Extrusion(
            Rectangle.from_center_and_sides(s.origin, length, width), height
        )
        rounded = Fillet(
            solid=block,
            radius=corner_r,
            edge_finder=EdgeFinder(rule=ParallelToAxisRule(axis="Z")),
        )
        self.add_operation(Shell(solid=rounded, thickness=wall))
        self.paint("light_bluish_gray")


show(RoundedEnclosure())