Regular Polygon

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


class GearLikeStack(Assembly):
    def __init__(self):
        for i, n_sides in enumerate([3, 5, 7, 12]):
            class _P(Part):
                def __init__(self, n=n_sides, z=i * 6):
                    s = Sketch(self.xy())
                    # RegularPolygon(center, n_sides, radius) inscribes
                    # an n-gon in a circle of given radius.
                    poly = RegularPolygon(s.origin, n_sides=n, radius=10)
                    self.add_operation(Extrusion(poly, end=4))
                    self.translate([0, 0, z])
                    self.paint(["bright_red", "bright_orange",
                                "bright_yellow", "bright_green"][i])
            self.add_component(_P())


show(GearLikeStack())

RegularPolygon(center, n_sides, radius) is a 2D primitive: an n_sides-gon inscribed in a circle of radius around center. It expands to a Polygon of N lines and composes with Extrusion, Lathe, Loft, and Sweep.

s = Sketch(self.xy())
                    # RegularPolygon(center, n_sides, radius) inscribes
                    # an n-gon in a circle of given radius.
                    poly = RegularPolygon(s.origin, n_sides=n, radius=10)
                    self.add_operation(Extrusion(poly, end=4))
                    self.translate([0, 0, z])

Hexagons stay available as the Hexagon(center, radius) shorthand; RegularPolygon is the generalization for any side count.