FoundationPartsOperationsMove & copy bodies

Move & copy bodies

MoveBody(shape, translation, rotation_angle=…, rotation_axis=…, rotation_origin=…) rotates a solid (degrees, about an axis through rotation_origin) and then translates it.

There is no separate “copy” operation: union a body with moved versions of itself, as the pegs above do with BooleanOperation(peg, [shifted, tipped], BooleanOp.UNION).

from cadbuildr.foundation import *


class MovedPegs(Part):
    """MoveBody moves (and rotates) a solid. Union a body with a moved copy of
    itself to duplicate it: here a peg, a copy 30 mm to the right, and a copy
    tipped over 90° about the Y axis."""

    def __init__(self):
        s = Sketch(self.xy())
        peg = Extrusion(Circle(s.origin, 5), 20)
        shifted = MoveBody(peg, Point3D(30, 0, 0))
        tipped = MoveBody(
            peg,
            Point3D(60, 0, 5),
            rotation_angle=90,
            rotation_axis=Point3D(0, 1, 0),
        )
        self.add_operation(BooleanOperation(peg, [shifted, tipped], BooleanOp.UNION))
        self.translate([-40, 0, 0])  # centre the three pegs in the viewer
        self.paint("tan")


show(MovedPegs())