3D printing

Design parts that print right the first time. Printed holes come out small, the first layer squishes out, two bodies printed too close fuse together, and a snap hook printed upright can break. The cadbuildr-print3d library keeps those rules in printer and material profiles. Its features and parts read them, and check() tells you what will fail before you slice.

Prerequisites: pip install cadbuildr-print3d (it installs cadbuildr-foundation and cadbuildr-stdlib).

from cadbuildr.foundation import show
from cadbuildr.print3d import PrintedCase, check
 
case = PrintedCase(width=90, depth=60, height=30, screw="M3", material="PETG")
for issue in check(case):
    print(issue["severity"], issue["code"], issue["message"])
show(case)

PrintedCase is an assembly of a box (CaseBase), a lid (CaseLid), four brass heat-set inserts and four stdlib DIN 912 screws. Every part is placed by connect: the lid on the rim, the inserts in the corner bosses and the screws in the lid holes. Each snap hook on the lid also connects to its window in the box wall. That connect closes a loop, so a clean check() proves the hooks land in the windows.

The library sizes the parts from your inputs:

  • Hook length comes from the material’s strain limit. A PLA hook is longer than a PETG one.
  • Screw length is the longest standard length that grips the insert without bottoming out.
  • Insert holes and clearance holes come from the insert table and ISO 273, plus the printer’s hole compensation.

Pick a printer and a material

from cadbuildr.print3d import settings
 
s = settings("FDM 0.4 mm", "PLA")
s.hole(5)                # 5.2: model this to print a 5 mm hole
s.bore(8, "slide")       # a hole an 8 mm shaft slides in
s.peg(8, "tight")        # a printed peg for a printed 8 mm hole
s.gap("print_in_place")  # the gap two parts printed together need
PrintersMaterialsFit classes
FDM 0.4 mm, FDM 0.6 mm, FDM 0.25 mm, FDM 0.4 mm large, MSLA resin, SLS nylonPLA, PETG, ABS, ASA, PA12, PC, TPU 95A, Resin (tough)press, tight, slide, free, print_in_place

The values are conservative starting points. Pass overrides such as settings(None, "PETG", hole_compensation=0.3) once you have printed a fit test. Every library part also takes printer= and material= inputs.

Add printed features to your own part

Each feature cuts into the part that owns the anchor you give it (+Z points out of the face). It also adds the interface that the mating hardware connects to:

FeatureInterfaceConnects
HeatSetInsertHole(face, "M3")InsertSeatHeatSetInsert
ClearanceHole(face, "M4", depth)ScrewHolestdlib screw heads
PrintedCountersink(face, "M3", depth)ScrewHolecountersunk screws
NutTrap(face, "M3", inset=2, slot=(1, 0))ScrewHole on the floorstdlib HexNut
SelfTapBoss(face, "M3", height=8)ScrewHole(thread=True)screws that cut their own thread
PinHole(face, d=3, depth=6, fit="press")BoreDowelPin
TeardropHole(face, d=5, depth=40)nonea horizontal hole that needs no support
from cadbuildr.foundation import Assembly
from cadbuildr.stdlib.fasteners.nuts.hex_din934_part import HexNut
 
asm = Assembly()
asm.ground(bracket)  # bracket has NutTrap(bracket.anchor("nut"), "M3")
asm.connect(HexNut(size="M3").interface("bottom"), bracket.interface("nut_floor"))
from cadbuildr.print3d import PrintInPlaceHinge, check
 
hinge = PrintInPlaceHinge(width=40, clearance=0.35, angle=60)
check(PrintInPlaceHinge(clearance=0.1))  # min_gap error: the knuckles would fuse

The two leaves print together, already assembled. The clearance input sets every gap between them: pin to bore, knuckle to knuckle, and leaf to knuckle. The bore is a teardrop, so it prints without support. The angle input turns the socket leaf on its revolute joint.

Check before you slice

from cadbuildr.print3d import check, print_orientation
 
check(case)                         # every printed part, plus the assembly check
check(case, printer="MSLA resin")   # check against another printer
print_orientation(case_lid)         # which face goes on the bed, and why
CodeSeverityMeaning
bed_fiterrorThe part is bigger than the bed. The fix says to rotate it, lay it on another face, or split it.
min_wallerror or warningThe wall is thinner than one line (error) or two perimeters (warning).
min_gaperrorTwo bodies are close enough to fuse.
snap_strainerrorA snap hook bends past the material’s limit. The fix gives the minimum length.
overhang, bridgewarningThe part needs support, a chamfer or a teardrop.
materialwarningHeat-set inserts do not hold in this material (for example TPU).

Errors subclass Print3dError, and each message says what to change: PrintabilityError, SnapFitStrainError, FastenerFitError and UnknownProfile.