Bills of materials

Get a parts list, a cut list, a stock-cutting plan, the mass and the cost of any CADbuildr model. This is the cadbuildr-bom library, built on Foundation.

Prerequisites: pip install cadbuildr-bom (it installs cadbuildr-foundation). Standard parts come from cadbuildr-stdlib.

Build a BOM

from cadbuildr.foundation import Assembly
from cadbuildr.bom import build_bom
from cadbuildr.stdlib.fasteners.screws_and_bolts.din912_part import DIN912Screw
from cadbuildr.stdlib.fasteners.nuts.hex_din934_part import HexNut
from cadbuildr.stdlib.profiles.extrusions.alu_extrusion_part import AluExtrusion
 
 
class Kit(Assembly):
    def __init__(self):
        for _ in range(4):
            self.add_component(DIN912Screw(size="M6", length=20))
            self.add_component(HexNut(size="M6"))
        for length in (400, 400, 250):
            self.add_component(AluExtrusion(series="2020", length=length))
 
 
bom = build_bom(Kit())
print(bom.to_markdown())

Each standard part describes itself. The screws become one line, ISO4762-M6x20, with standard, steel and an estimated mass. The extrusions are stock: each row has a stock name and a cut length.

Parts with the same part number are one line, even if their geometry differs (a screw with and without a modelled thread). Parts with no part number group by name, material and dimensions, wherever they sit in the assembly.

Export

bom.export("csv", "bom.csv")
bom.export("md", "bom.md")
bom.export("json", "bom.json")    # schema cadbuildr-bom@2
bom.export("xlsx", "bom.xlsx")    # sheets: BOM, Cut list, Totals

Mass, cost and rollups

from cadbuildr.bom import PriceBook
 
book = PriceBook({
    "ISO4762-M6x20": 0.12,                                       # each
    "2020 aluminium extrusion": {"unit_cost": 8.0, "per": "m"},  # by the metre
})
priced = bom.priced(book)
priced.totals()                 # {"mass_kg": ..., "cost": {"EUR": ...}, "unknown_mass": [...], ...}
priced.rollup("top_category")   # Fasteners, Profiles, ...
priced.filter(procurement="buy")

Totals always list the rows whose mass or price nobody knows (unknown_mass, unknown_cost), so a total is never silently partial. Price keys match a row id, part number, designation or stock name. PriceBook.from_csv(text) loads key,unit_cost,per,vendor,sku,url columns.

Cut list and stock nesting

for cut in bom.cut_list():
    print(cut.stock, cut.length, cut.quantity)
 
plan = bom.nest({"2020 aluminium extrusion": [1000, 2000]}, kerf=3, trim=5)
print(plan.to_text())
2020 aluminium extrusion: buy 1 x 2000 mm (waste 47.5 %)
  bar 1 (2000): 400 + 400 + 250  | offcut 936.0

Nesting fills the longest bars first (first-fit decreasing), then shrinks each bar to the shortest stock length that still holds its cuts. A piece longer than every bar raises CutTooLongError with the piece named.

linked = bom.with_links("misumi", "digikey")

Links are vendor searches for the part number or stock name. Add your own vendor with register_vendor("myshop", "https://shop.example/search?q={q}"). Parts you make (procurement="make") get no links.

Describe your own parts

from cadbuildr.bom import set_bom, add_bom_line
 
set_bom(leg, stock="45x45 beech", cut_length=720, procurement="stock",
        material="beech", volume_mm3=45 * 45 * 720)
set_bom(motor_unit, part_number="NEMA17-40-KIT", explode=False)  # one line, not its parts
set_bom(construction_plane, exclude=True)
add_bom_line(chair, "Wood glue (PVA)", quantity=30, unit="ml")
FieldMeaning
part_number, designation, standard, categoryidentity; rows with a part number group by it
procurementbuy, make or stock
stock, cut_lengthstock the piece is cut from, length in mm
material, finishmaterial name (also gives density)
mass_kg or volume_mm3mass of one piece, or volume × material density
unit_cost, currency, vendorsprice and where to buy
unit, quantitypcs, m, ml, h… and amount per instance
explode, exclude, refone-line sub-assembly, leave out, reference designator

Library authors declare it once on the decorator, @part(..., bom={"part_number": "HINGE-{size}"}), or with a __bom__(self) method. A misspelled field raises BomContractError.

Bought parts you do not model

PurchasedPart is an envelope (box or cylinder) for a bought component, such as a power supply or a sensor. It carries its part number, vendor, SKU, price and mass into the BOM. It has bottom, top and center anchors, so you place it with connect like any other part.

from cadbuildr.bom import PurchasedPart
 
psu = PurchasedPart(part_number="PSU-24V-150W", designation="Power supply 24 V 150 W",
                    width=160, depth=98, height=38, unit_cost=24.0, mass_kg=0.6)

The cloud BOM task

On CADbuildr cloud, the bom task builds a project version and saves bom.json and bom.csv to the project’s artifacts. Its item ids stay the same across runs, so per-part follow-up tasks can use them as keys.

Next