Rib & Push/Pull

Renders the 3D model in your browser. The first run downloads the Python runtime (≈30 MB).
import math

from cadbuildr.foundation import *


class GussetedBracket(Part):
    """Rib + OffsetFace.

    A base plate and an upright plate are joined by a triangular Rib (gusset)
    sketched on the YZ plane, and the upright's top face is pulled up 10 mm
    with OffsetFace (push/pull).
    """

    def __init__(self, thickness=5, upright=30):
        s = Sketch(self.xy())
        base = Extrusion(Rectangle.from_center_and_sides(s.origin, 40, 50), thickness)
        wall_s = Sketch(self.xy())
        wall = Extrusion(
            Rectangle.from_center_and_sides(Point(wall_s, 0, -22.5), 40, thickness),
            upright,
        )
        side = Sketch(self.yz())
        rib = Rib(
            [
                Point(side, -20, thickness),
                Point(side, 15, thickness),
                Point(side, -20, upright),
            ],
            4,
        )
        body = BooleanOperation(base, [wall, rib.expand()], BooleanOp.UNION)
        top = FaceFinder(rule=InPlaneFinderRule(self.xy(), upright))
        self.add_operation(OffsetFace(body, top, 10))
        self.rotate(math.pi)  # upright at the back, so the camera sees the gusset
        self.paint("medium_azure")


class GrownBoss(Part):
    """OffsetFace on a curved face: the side of a Ø16 boss is pushed out 3 mm,
    so the boss becomes Ø22. It still rises straight out of the plate and
    keeps its flat top. Picking one point on the side moves the whole
    cylinder."""

    def __init__(self, radius=8, height=20, plate=5, grow=3):
        s = Sketch(self.xy())
        base = Extrusion(Rectangle.from_center_and_sides(s.origin, 50, 40), plate)
        top = Sketch(self.xy().get_parallel_plane(plate))
        boss = Extrusion(Circle(top.origin, radius), height)
        body = BooleanOperation(base, [boss], BooleanOp.UNION)
        side = FaceFinder(
            rule=ContainsPointFinderRule(Point3D(0, radius, plate + height / 2))
        )
        self.add_operation(OffsetFace(body, side, grow))
        self.translate([60, 0, 0])
        self.paint("light_green")


class SlimmedCone(Part):
    """A negative OffsetFace on a cone: a frustum (r 10 → 6, 16 tall) has its
    conical face pulled in 1.5 mm. Both radii shrink by 1.5 / cos(half-angle)
    while the flat top and base stay where they were."""

    def __init__(self, r_base=10, r_top=6, height=16, pull=-1.5):
        s = Sketch(self.xz())
        axis = Axis(Line(Point(s, 0, -5), Point(s, 0, height + 5)))
        corners = [
            Point(s, 0, 0),
            Point(s, r_base, 0),
            Point(s, r_top, height),
            Point(s, 0, height),
        ]
        profile = Polygon(
            [Line(p, q) for p, q in zip(corners, corners[1:] + corners[:1])]
        )
        frustum = Lathe(profile, axis)
        mid_r = (r_base + r_top) / 2
        cone = FaceFinder(rule=ContainsPointFinderRule(Point3D(0, mid_r, height / 2)))
        self.add_operation(OffsetFace(frustum, cone, pull))
        self.translate([-60, 0, 0])
        self.paint("dark_orange")


class RibOffsetFaceExamples(Assembly):
    def __init__(self):
        self.add_component(GussetedBracket())
        self.add_component(GrownBoss())
        self.add_component(SlimmedCone())


show(RibOffsetFaceExamples())
  • Rib(points, thickness) fills the area between an open polyline and the straight line joining its ends, and extrudes it thickness symmetrically about its sketch plane. Three points make the classic triangular gusset, as between the two plates above. A Rib expands into an Extrusion, so use rib.expand() inside a BooleanOperation, or add it straight to the part.
  • OffsetFace(solid, face_finder, distance) pushes or pulls faces along their outward normal: positive distance grows the solid, negative cuts into it. Here the upright’s top face is pulled up 10 mm.
  • Curved faces move too, by their true offset. The green boss’s cylindrical side is pushed out 3 mm, so the Ø16 boss becomes Ø22. The orange frustum’s cone is pulled in 1.5 mm. In both cases the flat faces around the moved face are extended to meet it, so the boss still rises straight from its plate and the cone keeps its flat top and base. Cylinders, cones and spheres are offset exactly. An extruded circle’s side is two half faces, and picking either half moves the whole cylinder.
import math

from cadbuildr.foundation import *


class GussetedBracket(Part):
    """Rib + OffsetFace.

    A base plate and an upright plate are joined by a triangular Rib (gusset)
    sketched on the YZ plane, and the upright's top face is pulled up 10 mm
    with OffsetFace (push/pull).
    """

    def __init__(self, thickness=5, upright=30):
        s = Sketch(self.xy())
        base = Extrusion(Rectangle.from_center_and_sides(s.origin, 40, 50), thickness)
        wall_s = Sketch(self.xy())
        wall = Extrusion(
            Rectangle.from_center_and_sides(Point(wall_s, 0, -22.5), 40, thickness),
            upright,
        )
        side = Sketch(self.yz())
        rib = Rib(
            [
                Point(side, -20, thickness),
                Point(side, 15, thickness),
                Point(side, -20, upright),
            ],
            4,
        )
        body = BooleanOperation(base, [wall, rib.expand()], BooleanOp.UNION)
        top = FaceFinder(rule=InPlaneFinderRule(self.xy(), upright))
        self.add_operation(OffsetFace(body, top, 10))
        self.rotate(math.pi)  # upright at the back, so the camera sees the gusset
        self.paint("medium_azure")


class GrownBoss(Part):
    """OffsetFace on a curved face: the side of a Ø16 boss is pushed out 3 mm,
    so the boss becomes Ø22. It still rises straight out of the plate and
    keeps its flat top. Picking one point on the side moves the whole
    cylinder."""

    def __init__(self, radius=8, height=20, plate=5, grow=3):
        s = Sketch(self.xy())
        base = Extrusion(Rectangle.from_center_and_sides(s.origin, 50, 40), plate)
        top = Sketch(self.xy().get_parallel_plane(plate))
        boss = Extrusion(Circle(top.origin, radius), height)
        body = BooleanOperation(base, [boss], BooleanOp.UNION)
        side = FaceFinder(
            rule=ContainsPointFinderRule(Point3D(0, radius, plate + height / 2))
        )
        self.add_operation(OffsetFace(body, side, grow))
        self.translate([60, 0, 0])
        self.paint("light_green")


class SlimmedCone(Part):
    """A negative OffsetFace on a cone: a frustum (r 10 → 6, 16 tall) has its
    conical face pulled in 1.5 mm. Both radii shrink by 1.5 / cos(half-angle)
    while the flat top and base stay where they were."""

    def __init__(self, r_base=10, r_top=6, height=16, pull=-1.5):
        s = Sketch(self.xz())
        axis = Axis(Line(Point(s, 0, -5), Point(s, 0, height + 5)))
        corners = [
            Point(s, 0, 0),
            Point(s, r_base, 0),
            Point(s, r_top, height),
            Point(s, 0, height),
        ]
        profile = Polygon(
            [Line(p, q) for p, q in zip(corners, corners[1:] + corners[:1])]
        )
        frustum = Lathe(profile, axis)
        mid_r = (r_base + r_top) / 2
        cone = FaceFinder(rule=ContainsPointFinderRule(Point3D(0, mid_r, height / 2)))
        self.add_operation(OffsetFace(frustum, cone, pull))
        self.translate([-60, 0, 0])
        self.paint("dark_orange")


class RibOffsetFaceExamples(Assembly):
    def __init__(self):
        self.add_component(GussetedBracket())
        self.add_component(GrownBoss())
        self.add_component(SlimmedCone())


show(RibOffsetFaceExamples())

Direct edit: move and delete faces

Like Onshape’s Move face and Delete face, these edit a solid’s faces directly, whatever features built them.

  • MoveFace(solid, face_finder, translation=Point3D(…), rotation_angle=0, rotation_axis=Point3D(0, 0, 1), rotation_origin=Point3D(0, 0, 0)) moves planar faces to a new plane. The rotation is applied first, then the translation. The faces around the moved one extend or shrink to meet it: lengthen or shorten a block, raise a boss, make a pocket deeper, tilt an end face. Only the face’s new plane matters, so sliding a face within its own plane changes nothing.
  • DeleteFace(solid, face_finder) deletes the faces of a feature and heals the solid. Pick a hole’s wall (plus its floor if it is blind), a pocket’s or slot’s walls and floor, or a boss’s wall and top: the hole or pocket is filled, the boss is removed. Picking either half of an extruded circle’s side deletes the whole cylinder.
Renders the 3D model in your browser. The first run downloads the Python runtime (≈30 MB).
from cadbuildr.foundation import *


def face_at(x, y, z):
    """The face of the solid through the point (x, y, z)."""
    return FaceFinder(ContainsPointFinderRule(Point3D(x, y, z)))


def drilled_block(part):
    """30 x 24 x 16 block (z 0..16) with a Ø8 through hole at x = 6."""
    s = Sketch(part.xy())
    block = Extrusion([Rectangle.from_center_and_sides(s.origin, 30, 24)], 16)
    hole = Extrusion([Circle(Point(s, 6, 0), 4)], 16)
    return BooleanOperation(block, [hole], BooleanOp.SUBTRACT)


class Lengthened(Part):
    """MoveFace: the +X end face moves 12 mm out; top, bottom and sides follow."""

    def __init__(self):
        body = drilled_block(self)
        self.add_operation(
            MoveFace(body, face_at(15, 0, 8), translation=Point3D(12, 0, 0))
        )
        self.translate([-50, 0, 0])
        self.paint("light_blue")


class Tilted(Part):
    """MoveFace with a rotation: the top face tilts 15 degrees about Y through its middle."""

    def __init__(self):
        body = drilled_block(self)
        self.add_operation(
            MoveFace(
                body,
                face_at(-10, 0, 16),
                rotation_angle=15,
                rotation_axis=Point3D(0, 1, 0),
                rotation_origin=Point3D(0, 0, 16),
            )
        )
        self.paint("dark_orange")


class Healed(Part):
    """DeleteFace: picking the hole's wall deletes it and fills the hole."""

    def __init__(self):
        body = drilled_block(self)
        self.add_operation(DeleteFace(body, face_at(10, 0, 8)))
        self.translate([45, 0, 0])
        self.paint("lime")


class DirectEditFaces(Assembly):
    def __init__(self):
        self.add_component(Lengthened())
        self.add_component(Tilted())
        self.add_component(Healed())


show(DirectEditFaces())

From left to right: the block’s end face is moved out 12 mm, the top face is tilted 15°, and the hole’s wall is deleted, so the hole is filled.

How it works, and its limits

The OpenCascade defeaturing algorithm (BRepAlgoAPI_Defeaturing) is not in this build, so both are rebuilt with booleans:

  • MoveFace adds the face’s own prism, clipped by the new plane, and removes the slab beyond the new plane. This is only correct when the neighbouring faces run along the face’s normal, as in a prismatic region: side walls, or a cylinder parallel to the normal. These cases are processing errors:
    • a curved face (use OffsetFace instead);
    • drafted or sloped neighbours;
    • a tilt of more than 60°;
    • a face moved inward through another face.
  • DeleteFace closes the picked faces with flat caps over the loops where they meet the rest of the solid. It fills the result if it lies outside the solid and cuts it away if it lies inside. Those loops must be planar, so deleting a fillet or chamfer face is a processing error.
  • ReplaceFace (replace a face by another surface) is not available yet.
from cadbuildr.foundation import *


def face_at(x, y, z):
    """The face of the solid through the point (x, y, z)."""
    return FaceFinder(ContainsPointFinderRule(Point3D(x, y, z)))


def drilled_block(part):
    """30 x 24 x 16 block (z 0..16) with a Ø8 through hole at x = 6."""
    s = Sketch(part.xy())
    block = Extrusion([Rectangle.from_center_and_sides(s.origin, 30, 24)], 16)
    hole = Extrusion([Circle(Point(s, 6, 0), 4)], 16)
    return BooleanOperation(block, [hole], BooleanOp.SUBTRACT)


class Lengthened(Part):
    """MoveFace: the +X end face moves 12 mm out; top, bottom and sides follow."""

    def __init__(self):
        body = drilled_block(self)
        self.add_operation(
            MoveFace(body, face_at(15, 0, 8), translation=Point3D(12, 0, 0))
        )
        self.translate([-50, 0, 0])
        self.paint("light_blue")


class Tilted(Part):
    """MoveFace with a rotation: the top face tilts 15 degrees about Y through its middle."""

    def __init__(self):
        body = drilled_block(self)
        self.add_operation(
            MoveFace(
                body,
                face_at(-10, 0, 16),
                rotation_angle=15,
                rotation_axis=Point3D(0, 1, 0),
                rotation_origin=Point3D(0, 0, 16),
            )
        )
        self.paint("dark_orange")


class Healed(Part):
    """DeleteFace: picking the hole's wall deletes it and fills the hole."""

    def __init__(self):
        body = drilled_block(self)
        self.add_operation(DeleteFace(body, face_at(10, 0, 8)))
        self.translate([45, 0, 0])
        self.paint("lime")


class DirectEditFaces(Assembly):
    def __init__(self):
        self.add_component(Lengthened())
        self.add_component(Tilted())
        self.add_component(Healed())


show(DirectEditFaces())