"""PCB support (board spacer post), four kinds, M2 to M4 sizes, any height: as step.parts' published models draw them. A solid round post on a round flange, standing on the XY plane at the origin along +Z, the board seat at `height`: - snap-in: flange on z = 0, post to `height`, a round snap head above it (the board sits on the post's top); - adhesive: a square adhesive pad on z = 0, then the flange and the post to `height`; - swage, press-fit: flange on z = 0 and the post to `height` (the models of the two kinds are identical). The posts are solid: the models show no bore, thread, barbs or knurl. See the README. """ from steve import Model kind = "snap-in" # Kind: snap-in, adhesive, swage, press-fit size = "M3" # Size (board hole / screw) height = 10 # mm Height (board seat above the base) material = "unspecified" # Material # mm, measured on step.parts' models _pcb_support|standoff__h (every face read: cylinder radii and # their faces' z-ranges, the pad's planar faces); the same for every height of a size: # size: (flange diameter, flange top z, post diameter, snap head diameter, snap head height, pad side, pad thickness) SIZES = { "M2": (5.0, 1.5, 2.5, 4.0, 1.5, 10.0, 1.0), "M2.5": (6.25, 1.5, 3.0, 5.0, 1.5, 10.0, 1.0), "M3": (7.5, 1.5, 3.6, 6.0, 1.8, 12.0, 1.0), "M4": (10.0, 2.0, 4.8, 8.0, 2.4, 16.0, 1.0), } # material choice: (STEVE material library id, appearance colour); the models name no material MATERIALS = { "unspecified": (None, None), "nylon": ("pa6", "#ece9e1"), "brass": ("brass", "#c6a75a"), "steel": ("steel-generic", "#9da2a8"), } flange_d, flange_top, post_d, head_d, head_h, pad, pad_t = SIZES[size] if height <= flange_top: raise ValueError(f"The height must be more than the flange's top ({flange_top} mm).") material_id, colour = MATERIALS[material] model = Model() base = pad_t if kind == "adhesive" else 0.0 if kind == "adhesive": model.box("pad", pad, pad, pad_t, at=(0, 0, pad_t / 2), name="Adhesive pad") model.cylinder("flange", flange_d / 2, flange_top - base, at=(0, 0, base), op="join" if kind == "adhesive" else None, name="Flange") model.cylinder("post", post_d / 2, height - flange_top, at=(0, 0, flange_top), op="join", name="Post") if kind == "snap-in": model.cylinder("head", head_d / 2, head_h, at=(0, 0, height), op="join", name="Snap head") if material_id: model.material(material_id, color=colour) result = model.result()