Standard parts (stdlib)
Order hardware the way you would from a catalogue: pick a screw, a bearing,
a rail or a motor by its designation, and connect it to your parts by its
mating sites instead of computing positions. This is the cadbuildr-stdlib
library, built on Foundation. Browse every part live at
cadbuildr.github.io/stdlib.
Prerequisites: pip install cadbuildr-stdlib (it installs
cadbuildr-foundation).
Get a part
Every part takes the catalogue designation and, when the catalogue has one, a length:
from cadbuildr.foundation import show
from cadbuildr.stdlib.fasteners import DIN912Screw, SetScrew, HeatSetInsert
from cadbuildr.stdlib.bearings import PillowBlock
from cadbuildr.stdlib.linear_motion.rails import LinearRail
show(DIN912Screw(size="M4", length=16)) # socket head cap screw, 16 mm under the head
show(SetScrew(size="M3", length=4, point="cup"))
show(HeatSetInsert(size="M3"))
show(PillowBlock(model="KP08"))
show(LinearRail(series="MGN12", length=300))A size the standard does not define fails with the valid choices:
ValueError: SetScrew: unknown size 'M7' (choose from M3, M4, M5, M6, M8, M10, M12).| Family | Parts |
|---|---|
| Screws | cap (DIN 912), hex bolt (DIN 933/931), button (ISO 7380), countersunk (DIN 7991, DIN 963), cheese head (DIN 84), pan head Phillips (ISO 7045), set screws (ISO 4026–4029), wood screws |
| Nuts, washers | hex, thin, nylon lock, square, wing, T-slot nuts; flat, split lock, fender washers |
| Inserts, pins, spacers | heat-set inserts M2–M6, dowel pins (ISO 8734), hex standoffs |
| Bearings | deep groove, flanged, thrust, KP pillow blocks |
| Linear motion | smooth rods, LMxUU bearings, SK supports, T8 lead screw + nut, MGN rails and carriages |
| Power transmission | spur gears, racks, GT2 pulleys, clamp couplings, shafts |
| Motors | NEMA 14/17/23 steppers, SG90 / MG90S / MG996R servos |
| Profiles | 2020 / 2040 T-slot extrusion, round tube |
To list everything with its inputs, run
python -m cadbuildr.foundation.library manifest cadbuildr.stdlib.
Connect parts by their interfaces
Each part carries named interfaces: a screw has a ScrewHead, a
bearing a Bore, a motor shaft a ShaftEnd, a rail a RailTrack.
assembly.connect joins two of them with the right joint and checks that
they fit (an 8 mm bore on a 5 mm shaft is refused):
from cadbuildr.foundation import Assembly, show
from cadbuildr.stdlib.actuators.stepper_motors.nema_stepper_part import StepperMotor
from cadbuildr.stdlib.power_transmission.couplings.clamp_coupling_part import ClampCoupling
from cadbuildr.stdlib.linear_motion.lead_screws.lead_screw_part import LeadScrewT8, LeadScrewNutT8
motor = StepperMotor("NEMA17")
coupling = ClampCoupling(bore_a=5, bore_b=8)
screw = LeadScrewT8(length=200)
nut = LeadScrewNutT8()
z_axis = Assembly()
z_axis.ground(motor)
z_axis.connect(motor.interface("shaft_tip"), coupling.interface("bore_a_stop"))
z_axis.connect(screw.interface("end_a"), coupling.interface("bore_b_stop"))
z_axis.connect(screw.interface("axis"), nut.interface("axis"), offset=120)
print(z_axis.check()) # only "nut moves (offset 120)": nothing left unconnected
show(z_axis)Fasten, mesh and slide in one call
| Helper | Does |
|---|---|
connect_with_screw(asm, screw, hole_anchor) | seats the head on the face and drills the clearance hole; into= + into_depth= also taps the part underneath |
connect_with_bolt_and_nut(asm, bolt, nut, hole_anchor, grip=8) | through-bolt with optional washers; refuses a bolt that is too short |
connect_heat_set_insert(asm, insert, face_anchor) | insert flush in the face, pocket cut |
mesh_gears(asm, pinion, wheel) | wheel at the centre distance, a tooth in a gap |
mesh_rack(asm, pinion, rack, pinion_joint) | rack tangent to the pinion; turning the pinion slides the rack |
mount_carriage(asm, rail, carriage, at=100) | carriage on its rail, sliding along it |
from cadbuildr.foundation import show
from cadbuildr.stdlib.examples import build_rack_and_pinion
assembly, parts, joints = build_rack_and_pinion()
joints["spin"].set_angle(1.0) # one radian
print(joints["slide"].offset.value) # 10.0 mm: pitch radius x angle
show(assembly)Worked examples
cadbuildr.stdlib.examples has small, complete assemblies to copy from:
bolted_plate, motor_leadscrew_stack, gear_pair, rack_and_pinion,
rail_slide (MGN12 rail screwed to a base, carriage on a slider) and
pcb_on_standoffs (heat-set inserts, standoffs and pan head screws holding
a board). Each build_<name>() also returns the parts and joints.
Lengths
length is what the catalogue lists: under the head for cap, button,
pan head and cheese head screws and hex bolts; overall for countersunk,
wood and set screws, which sit flush.