Foundation (Python)ReferenceOperationsPatterns (Linear, Polar & Curve)

Patterns (Linear, Polar & Curve)

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


class BoltCircleFlange(Part):
    """LinearPattern and PolarPattern of solid features.

    Six bolt holes are one cut Extrusion repeated by a PolarPattern (the
    pattern inherits `cut=True`), and four stiffening ribs are one rib repeated
    by a LinearPattern.
    """

    def __init__(self, radius=40, thickness=8, holes=6, ribs=4):
        s = Sketch(self.xy())
        self.add_operation(Extrusion(Circle(s.origin, radius), thickness))

        hole = Extrusion(Circle(Point(s, 30, 0), 3), thickness, cut=True)
        self.add_operation(PolarPattern(hole, holes))

        top = Sketch(self.xy().get_parallel_plane(thickness))
        rib = Extrusion(Rectangle.from_center_and_sides(Point(top, -12, 0), 2, 30), 5)
        self.add_operation(LinearPattern(rib, Point3D(1, 0, 0), ribs, 8))
        self.paint("medium_azure")


show(BoltCircleFlange())

LinearPattern(shape, direction, count, spacing) repeats a solid along a direction; PolarPattern(shape, count, angle=360) repeats it around an axis (Z through the origin by default — set axis_origin / axis_direction). The first copy is the original, so add only the pattern to the part.

Patterning a cutting feature patterns the cut: the six bolt holes above are a single Extrusion(..., cut=True) inside a PolarPattern. With the default angle=360 the copies are spread evenly; with a smaller angle the first and last copies sit at 0° and angle.

These are 3D patterns of solids. To repeat 2D shapes inside a sketch, see Sketch operations.

from cadbuildr.foundation import *


class BoltCircleFlange(Part):
    """LinearPattern and PolarPattern of solid features.

    Six bolt holes are one cut Extrusion repeated by a PolarPattern (the
    pattern inherits `cut=True`), and four stiffening ribs are one rib repeated
    by a LinearPattern.
    """

    def __init__(self, radius=40, thickness=8, holes=6, ribs=4):
        s = Sketch(self.xy())
        self.add_operation(Extrusion(Circle(s.origin, radius), thickness))

        hole = Extrusion(Circle(Point(s, 30, 0), 3), thickness, cut=True)
        self.add_operation(PolarPattern(hole, holes))

        top = Sketch(self.xy().get_parallel_plane(thickness))
        rib = Extrusion(Rectangle.from_center_and_sides(Point(top, -12, 0), 2, 30), 5)
        self.add_operation(LinearPattern(rib, Point3D(1, 0, 0), ribs, 8))
        self.paint("medium_azure")


show(BoltCircleFlange())

Grids and curve patterns

LinearPattern takes an optional second direction: direction2, count2 and spacing2 repeat every copy along it too, for a count × count2 grid (self.linear_pattern(hole, [1, 0, 0], 2, 44, direction2=[0, 1, 0], count2=2, spacing2=44) drills the 2 × 2 corner holes below). Without them the pattern is the one-direction pattern it always was.

CurvePattern(shape, path, count, align_to_path=False) (shortcut self.curve_pattern(...)) places copies along a 3D path — a Spline3D (two points make a straight path) or a Helix3D — evenly spaced by arc length:

  • the first copy is the original: draw it at the start of the path. Every copy keeps the seed’s offset from the path point it sits on;
  • on an open path the copies run from the start to the end; on a closed one (start = end) they are spread evenly around it;
  • align_to_path=True also turns each copy with the path — the steps below keep pointing at the column. Without it the copies are only moved.
Renders the 3D model in your browser. The first run downloads the Python runtime (≈30 MB).
from cadbuildr.foundation import *


class SpiralStair(Part):
    """A LinearPattern grid and a CurvePattern along a helix.

    The base plate gets a 2 x 2 grid of corner holes: one cut Extrusion repeated along
    X and, with direction2, along Y. The steps are one radial block at the
    start of a helix, repeated along it with align_to_path=True so every step
    turns with the stair and keeps pointing at the column.
    """

    def __init__(self, plate=60, thickness=3, steps=9, rise=36, turn=0.8):
        s = Sketch(self.xy())
        self.extrude(Rectangle.from_center_and_sides(s.origin, plate, plate), thickness)

        hole = Extrusion(Circle(Point(s, -22, -22), 2), thickness, cut=True)
        self.linear_pattern(
            hole, [1, 0, 0], 2, 44, direction2=[0, 1, 0], count2=2, spacing2=44
        )

        self.add_operation(
            Extrusion(Circle(s.origin, 4), thickness + rise + 2, thickness)
        )

        step = Extrusion(
            Rectangle.from_center_and_sides(Point(s, 11, 0), 14, 6),
            thickness + 1.5,
            thickness,
        )
        helix = Helix3D(
            rise / turn, rise, 11, Point3D(0, 0, thickness), Point3D(0, 0, 1)
        )
        self.curve_pattern(step, helix, steps, align_to_path=True)
        self.paint("light_bluish_gray")


show(SpiralStair())

Pattern the whole body

Pass shape=None to repeat the part’s body built so far instead of one feature (Onshape’s body pattern), e.g. self.linear_pattern(None, [1, 0, 0], 3, 10) after building a post makes three posts. As with fillet_edges, it works on every operation before it, and later operations apply on top.

from cadbuildr.foundation import *


class SpiralStair(Part):
    """A LinearPattern grid and a CurvePattern along a helix.

    The base plate gets a 2 x 2 grid of corner holes: one cut Extrusion repeated along
    X and, with direction2, along Y. The steps are one radial block at the
    start of a helix, repeated along it with align_to_path=True so every step
    turns with the stair and keeps pointing at the column.
    """

    def __init__(self, plate=60, thickness=3, steps=9, rise=36, turn=0.8):
        s = Sketch(self.xy())
        self.extrude(Rectangle.from_center_and_sides(s.origin, plate, plate), thickness)

        hole = Extrusion(Circle(Point(s, -22, -22), 2), thickness, cut=True)
        self.linear_pattern(
            hole, [1, 0, 0], 2, 44, direction2=[0, 1, 0], count2=2, spacing2=44
        )

        self.add_operation(
            Extrusion(Circle(s.origin, 4), thickness + rise + 2, thickness)
        )

        step = Extrusion(
            Rectangle.from_center_and_sides(Point(s, 11, 0), 14, 6),
            thickness + 1.5,
            thickness,
        )
        helix = Helix3D(
            rise / turn, rise, 11, Point3D(0, 0, thickness), Point3D(0, 0, 1)
        )
        self.curve_pattern(step, helix, steps, align_to_path=True)
        self.paint("light_bluish_gray")


show(SpiralStair())