Quantity Takeoff

A quantity schedule of a brick and block house shell, computed from the model: the kernel measures the net volume of each element after the openings are cut, and the schedule groups the volumes by category and material. The brick and block sizes, the joint and the stair limits are published figures, and the console compares the brick and block counts with the guide figures of 60 and 10 for each square metre. The plan, the openings, the joists and the roof are a display model. The Files button saves the schedule as CSV.
Code
This is the full program. The playground runs it in your browser without a change.
ts
import { BimModel, placedSolids, toIfc } from 'brepjs-bim';
import { box, compound, measureVolume, unwrap } from 'brepjs/quick';
import { color, present } from 'brepjs/playground';
// Quantity takeoff of a brick and block house shell. The kernel measures the net volume of each element
// after the openings are cut, and the schedule groups the volumes by category and material.
// Units are millimetres. X is along the front, Y is to the back, Z is up.
interface TakeoffParams {
storeys?: 1 | 2;
cutaway?: boolean; // leave the east wall and half of the roof finish out of the view. The model keeps them
}
// ---- published figures
const BRICK = { length: 215, width: 102.5, height: 65, joint: 10, guidePerM2: 60 }; // work size and joint
const BLOCK = { length: 440, width: 100, height: 215, joint: 10, guidePerM2: 10 };
const STAIR_LIMIT = { rise: 220, going: 220, pitch: 42 }; // private stair: largest rise, smallest going, largest pitch
// ---- display model
const CO = { x: BRICK.length + BRICK.joint, z: BRICK.height + BRICK.joint }; // one brick with its joints: 225 by 75
const PLAN = { x: 36 * CO.x, y: 27 * CO.x }; // 8100 by 6075: whole bricks on each side
const STOREY = 36 * CO.z; // 2700: whole courses
const CAVITY = 100;
const INNER = BRICK.width + CAVITY; // from the outside face to the block leaf
const WALL = INNER + BLOCK.width; // the cavity wall: 302.5
const SPINE = { x: 4000, width: BLOCK.width }; // the block wall that carries the joists at the middle
const JOIST = { width: 47, depth: 195, spacing: 400, deck: 22 };
const STAIR = { risers: 13, going: 240, width: 900, y: 1200 };
const FOOTING = { width: 600, depth: 225, top: -900 };
const PARAPET = 6 * CO.z;
const ROOF = { insulation: 120, membrane: 6 };
const MATERIAL = {
brick: 'Facing brick', block: 'Concrete block', trench: 'Foundation block', concrete: 'Concrete C25/30',
timber: 'Softwood C24', deck: 'Chipboard P5', stair: 'Precast concrete stair', insulation: 'PIR insulation',
membrane: 'Roof membrane', coping: 'Precast coping', guard: 'Softwood balustrade',
};
const TINT: Record<string, string> = {
[MATERIAL.brick]: '#b9623c', [MATERIAL.block]: '#cfcabb', [MATERIAL.trench]: '#8f897e', [MATERIAL.concrete]: '#a8a294',
[MATERIAL.timber]: '#d3a956', [MATERIAL.deck]: '#c9b48a', [MATERIAL.stair]: '#8a99ad', [MATERIAL.insulation]: '#e9d98a',
[MATERIAL.membrane]: '#48515c', [MATERIAL.coping]: '#f5f2ea', [MATERIAL.guard]: '#f5f2ea',
};
type P3 = [number, number, number];
type Side = 'south' | 'north' | 'west' | 'east';
type Id = Extract<ReturnType<BimModel['addSlab']>, { ok: true }>['value'];
type Body = ReturnType<typeof box>;
type Row = { category: string; material: string; count: number; m3: number };
type Opening = { side: Side; level: number; at: number; width: number; sill: number; height: number; door: boolean };
const X: P3 = [1, 0, 0], Y: P3 = [0, 1, 0], Z: P3 = [0, 0, 1];
// The model stays alive for the IFC file. Each temporary solid is freed, also when the build throws.
function takeoff({ storeys = 2, cutaway = true }: TakeoffParams = {}) {
const model = new BimModel(), owned: Body[] = [];
try {
const house = shell(model, storeys);
// ---- the takeoff. Each element gives its solid in its place, and the kernel measures the volume.
// The openings are already cut, so each figure is net. Group them the way a takeoff sheet does.
const rows = new Map<string, Row>(), groups = new Map<string, Body[]>();
for (const el of model.getAllElements()) {
const level = house.level.get(el.localId);
if (level === undefined) continue; // the site, the building and the storeys have no solid
const solids = unwrap(placedSolids(el, { parentFrame: { origin: [0, 0, level * STOREY], axisX: X, axisZ: Z } }));
owned.push(...solids);
if (solids.length === 0) continue; // a door or a window is a void in its wall
const material = (el.spec as { materialName?: string }).materialName ?? '(none)';
const key = el.category + '|' + material;
const row = rows.get(key) ?? { category: el.category, material, count: 0, m3: 0 };
row.count += 1;
for (const s of solids) row.m3 += unwrap(measureVolume(s)) / 1e9; // 1 m3 is 1e9 mm3
rows.set(key, row);
if (!(cutaway && house.hidden.has(el.localId))) groups.set(material, [...(groups.get(material) ?? []), ...solids]);
}
const ordered = [...rows.values()].sort((a, b) => b.m3 - a.m3);
// Masonry is ordered by number. Net volume / leaf thickness = net face area, and each unit covers its face and one joint.
const units = (material: string, unit: { length: number; width: number; height: number; joint: number }) => {
const net = (rows.get('WALL|' + material)?.m3 ?? 0) / (unit.width / 1000);
const gross = model.getWalls().filter((w) => w.spec.materialName === material).reduce((sum, w) => sum + (w.spec.length * w.spec.height) / 1e6, 0);
const perM2 = 1e6 / ((unit.length + unit.joint) * (unit.height + unit.joint));
return { gross, net, perM2, count: Math.ceil(net * perM2) };
};
const shown = [...groups].map(([material, solids]) => color(compound(solids), TINT[material] ?? '#8b8b8b'));
const dressed = dressing(house.openings, owned);
return { model, shown: [...shown, ...dressed], ordered, bricks: units(MATERIAL.brick, BRICK), blocks: units(MATERIAL.block, BLOCK), rise: STOREY / STAIR.risers };
} catch (error) {
model[Symbol.dispose]();
throw error;
} finally {
owned.splice(0).forEach((s) => s.delete());
}
}
// Show two storeys, cut open. Try takeoff({ storeys: 1 }), or takeoff({ cutaway: false }).
const job = takeoff();
console.log('category material count m3');
for (const r of job.ordered) console.log(r.category.padEnd(11) + r.material.padEnd(24) + String(r.count).padStart(5) + r.m3.toFixed(2).padStart(8));
const line = (name: string, u: typeof job.bricks, guide: number): string =>
name + ': gross ' + u.gross.toFixed(1) + ' m2, net ' + u.net.toFixed(1) + ' m2 = ' + u.count + ' at ' + u.perM2.toFixed(1) + ' for each m2 (guide figure ' + guide + '). Gross would order ' + Math.ceil((u.gross - u.net) * u.perM2) + ' too many';
console.log(line('bricks', job.bricks, BRICK.guidePerM2));
console.log(line('blocks', job.blocks, BLOCK.guidePerM2));
const pitch = (Math.atan(job.rise / STAIR.going) * 180) / Math.PI;
console.log('stair: rise ' + job.rise.toFixed(1) + ' mm (limit ' + STAIR_LIMIT.rise + '), going ' + STAIR.going + ' mm (limit ' + STAIR_LIMIT.going + '), pitch ' + pitch.toFixed(1) + ' deg (limit ' + STAIR_LIMIT.pitch + ')');
const csv = ['Category,Material,Count,NetVolume_m3']
.concat(job.ordered.map((r) => r.category + ',' + r.material + ',' + r.count + ',' + r.m3.toFixed(3)))
.join(String.fromCharCode(10));
// The IFC button saves the model. The Files button saves the schedule as CSV for a takeoff sheet.
export default present(job.shown, {
bimTree: job.model.toTreeSummary(),
ifc: async () => unwrap(await toIfc(job.model, { applicationName: 'brepjs playground', applicationVersion: '1.0' })),
files: () => [{ name: 'takeoff.csv', data: csv, mime: 'text/csv' }],
});
// ---- the building. Each element is in the frame of its storey: z = 0 is the top of the floor.
function shell(model: BimModel, storeys: number) {
model.init({ name: 'Takeoff demo', projectId: 'takeoff-demo' });
const site = unwrap(model.addSite({ name: 'Site' }));
const building = unwrap(model.addBuilding({ name: 'House' }));
const project = model.getProject();
if (project) model.aggregate(project.localId, site);
model.aggregate(site, building);
const levels = Array.from({ length: storeys + 1 }, (_, i) => {
const id = unwrap(model.addStorey({ name: i === storeys ? 'Roof' : i === 0 ? 'Ground floor' : 'Floor ' + i, elevation: i * STOREY }));
model.aggregate(building, id);
return id;
});
const level = new Map<Id, number>(), hidden = new Set<Id>(), openings: Opening[] = [];
const put = (at: number, made: ReturnType<BimModel['addSlab']>, hide = false): Id => {
const id = unwrap(made);
model.placeIn(id, levels[at]!);
level.set(id, at);
if (hide) hidden.add(id);
return id;
};
// The four rectangles of a ring of walls. Its outside is inset from the outline of the plan.
const ring = (inset: number, t: number): Record<Side, [number, number, number, number]> => ({
south: [inset, inset, PLAN.x - inset, inset + t],
north: [inset, PLAN.y - inset - t, PLAN.x - inset, PLAN.y - inset],
west: [inset, inset + t, inset + t, PLAN.y - inset - t],
east: [PLAN.x - inset - t, inset + t, PLAN.x - inset, PLAN.y - inset - t],
});
const SIDES: Side[] = ['south', 'north', 'west', 'east'];
// A wall puts its thickness on the left of its direction, so each side runs anticlockwise.
const leaf = (at: number, inset: number, t: number, z: number, height: number, materialName: string, above = true): Record<Side, Id> => {
const r = ring(inset, t), wall = { height, thickness: t, axisZ: Z, materialName, isExternal: true };
const run = (side: Side): Id => {
const [x0, y0, x1, y1] = r[side];
if (side === 'south') return put(at, model.addWall({ ...wall, length: x1 - x0, origin: [x0, y0, z], axisX: X }));
if (side === 'north') return put(at, model.addWall({ ...wall, length: x1 - x0, origin: [x1, y1, z], axisX: [-1, 0, 0] }));
if (side === 'west') return put(at, model.addWall({ ...wall, length: y1 - y0, origin: [x0, y1, z], axisX: [0, -1, 0] }));
return put(at, model.addWall({ ...wall, length: y1 - y0, origin: [x1, y0, z], axisX: Y }), above);
};
return { south: run('south'), north: run('north'), west: run('west'), east: run('east') };
};
const slab = (at: number, x0: number, y0: number, x1: number, y1: number, z: number, thickness: number, predefinedType: 'FLOOR' | 'ROOF' | 'BASESLAB', materialName: string, hide = false): Id =>
put(at, model.addSlab({ length: x1 - x0, width: y1 - y0, thickness, origin: [x0, y0, z], axisX: X, axisZ: Z, predefinedType, materialName }), hide);
// Below the ground: strip footings, foundation blocks up to the floor, and the ground slab between them.
const strip = { thickness: FOOTING.depth, axisX: X, axisZ: Z, predefinedType: 'STRIP_FOOTING', materialName: MATERIAL.concrete } as const;
const under = ring(WALL / 2 - FOOTING.width / 2, FOOTING.width);
for (const side of SIDES) {
const [x0, y0, x1, y1] = under[side];
put(0, model.addFooting({ ...strip, length: x1 - x0, width: y1 - y0, origin: [x0, y0, FOOTING.top - FOOTING.depth] }));
}
const inside = under.south[3];
put(0, model.addFooting({ ...strip, length: FOOTING.width, width: PLAN.y - 2 * inside, origin: [SPINE.x + SPINE.width / 2 - FOOTING.width / 2, inside, FOOTING.top - FOOTING.depth] }));
leaf(0, 0, WALL, FOOTING.top, -FOOTING.top, MATERIAL.trench, false);
const bays: [number, number][] = [[WALL, SPINE.x], [SPINE.x + SPINE.width, PLAN.x - WALL]];
const spineWall = { length: PLAN.y - 2 * WALL, thickness: SPINE.width, axisX: Y, axisZ: Z, materialName: MATERIAL.block };
put(0, model.addWall({ ...spineWall, height: -FOOTING.top, origin: [SPINE.x + SPINE.width, WALL, FOOTING.top] }));
for (const [x0, x1] of bays) slab(0, x0, WALL, x1, PLAN.y - WALL, -100, 100, 'BASESLAB', MATERIAL.concrete);
// Openings stand on the brick module. A cavity wall is two leaves, so each opening is cut in both.
const window = (side: Side, at: number, width: number, upper: boolean): Omit<Opening, 'level'> =>
({ side, at, width, sill: upper ? 12 * CO.z : 11 * CO.z, height: upper ? 16 * CO.z : 17 * CO.z, door: false });
const door = (side: Side, at: number, width: number): Omit<Opening, 'level'> => ({ side, at, width, sill: 0, height: 28 * CO.z, door: true });
const GROUND = [door('south', 5 * CO.x, 4 * CO.x + 10), window('south', 11 * CO.x, 5 * CO.x + 10, false), window('south', 23 * CO.x, 8 * CO.x + 10, false),
window('north', 6 * CO.x, 6 * CO.x + 10, false), door('north', 21 * CO.x, 8 * CO.x + 10), window('west', 11 * CO.x, 5 * CO.x + 10, false)];
const UPPER = [window('south', 4 * CO.x, 5 * CO.x + 10, true), window('south', 11 * CO.x, 5 * CO.x + 10, true), window('south', 24 * CO.x, 6 * CO.x + 10, true),
window('north', 6 * CO.x, 6 * CO.x + 10, true), window('north', 22 * CO.x, 6 * CO.x + 10, true), window('west', 11 * CO.x, 5 * CO.x + 10, true)];
for (let at = 0; at <= storeys; at++) {
const top = at === storeys;
if (at > 0) {
// The floor: joists on hangers between the walls, and a deck for each bay. The joists stop at the stairwell.
const depth = JOIST.depth, well = { y0: STAIR.y, y1: STAIR.y + STAIR.risers * STAIR.going, x: SPINE.x + SPINE.width + STAIR.width };
const joist = { profile: { kind: 'RECTANGULAR', width: JOIST.width, height: depth }, axisZ: Z, predefinedType: 'JOIST', materialName: MATERIAL.timber } as const;
const z = -JOIST.deck - depth / 2;
let before = WALL, after = PLAN.y - WALL;
bays.forEach(([x0, x1], bay) => {
for (let y = WALL + 50; y < PLAN.y - WALL - JOIST.width; y += JOIST.spacing) {
const cut = !top && bay === 1 && y + JOIST.width / 2 > well.y0 && y - JOIST.width / 2 < well.y1;
if (bay === 1 && !cut && y < well.y0) before = y + JOIST.width / 2;
if (bay === 1 && !cut && y > well.y1 && after > y) after = y - JOIST.width / 2;
const from = cut ? well.x + JOIST.width : x0;
put(at, model.addBeam({ ...joist, length: x1 - from, origin: [from, y, z], axisX: X }));
}
const deck = slab(at, x0, WALL, x1, PLAN.y - WALL, -JOIST.deck, JOIST.deck, top ? 'ROOF' : 'FLOOR', MATERIAL.deck, top && bay === 1);
if (!top && bay === 1) unwrap(model.addSlabOpening({ slabLocalId: deck, offsetX: 0, offsetY: well.y0 - WALL, sizeX: STAIR.width, sizeY: well.y1 - well.y0 }));
});
// The trimmer carries the cut joists at the side of the stairwell.
if (!top) put(at, model.addBeam({ ...joist, length: after - before, origin: [well.x + JOIST.width / 2, before, z], axisX: Y }));
// A guard on the two open sides of the stairwell.
const guard = { height: 900, thickness: JOIST.width, axisZ: Z, predefinedType: 'BALUSTRADE', infill: 'POSTED', materialName: MATERIAL.guard } as const;
if (!top) put(at, model.addRailing({ ...guard, length: well.y1 - well.y0 + JOIST.width, origin: [well.x + JOIST.width, well.y0 - JOIST.width, 0], axisX: Y }));
if (!top) put(at, model.addRailing({ ...guard, length: STAIR.width, origin: [well.x - STAIR.width, well.y0 - JOIST.width, 0], axisX: X }));
}
if (top) {
// The flat roof: a parapet of six courses with a coping, insulation on the deck and a membrane on top.
leaf(at, 0, BRICK.width, 0, PARAPET, MATERIAL.brick);
leaf(at, INNER, BLOCK.width, 0, PARAPET, MATERIAL.block);
const cap = ring(-24, WALL + 48), cover = { axisX: X, axisZ: Z, predefinedType: 'ROOFING' } as const;
for (const side of SIDES) {
const [x0, y0, x1, y1] = cap[side];
put(at, model.addCovering({ ...cover, length: x1 - x0, width: y1 - y0, thickness: 50, origin: [x0, y0, PARAPET], materialName: MATERIAL.coping }), side === 'east');
}
// The roof finish is in two parts that meet on the spine wall. The view leaves the east part off.
const middle = SPINE.x + SPINE.width / 2;
[[WALL, middle], [middle, PLAN.x - WALL]].forEach(([x0, x1], part) => {
const field = { ...cover, length: x1! - x0!, width: PLAN.y - 2 * WALL };
put(at, model.addCovering({ ...field, predefinedType: 'INSULATION', thickness: ROOF.insulation, origin: [x0!, WALL, 0], materialName: MATERIAL.insulation }), part === 1);
put(at, model.addCovering({ ...field, thickness: ROOF.membrane, origin: [x0!, WALL, ROOF.insulation], materialName: MATERIAL.membrane }), part === 1);
});
continue;
}
// The walls of one storey: a brick leaf, a block leaf, and the spine wall with a door.
const leaves = [leaf(at, 0, BRICK.width, 0, STOREY, MATERIAL.brick), leaf(at, INNER, BLOCK.width, 0, STOREY, MATERIAL.block)];
for (const o of at === 0 ? GROUND : UPPER) {
openings.push({ ...o, level: at });
leaves.forEach((ids, i) => {
const inset = i * INNER, t = i === 0 ? BRICK.width : BLOCK.width;
// The distance along a wall is from its own start: the north and the west wall run backward.
const offsetAlongWall = o.side === 'south' ? o.at - inset : o.side === 'north' ? PLAN.x - inset - o.at - o.width : PLAN.y - inset - t - o.at - o.width;
const hole = { wallLocalId: ids[o.side], width: o.width, height: o.height, offsetAlongWall, offsetFromFloor: o.sill, isExternal: true };
put(at, o.door ? model.addDoor({ ...hole, materialName: 'Timber door' }) : model.addWindow({ ...hole, materialName: 'Glazing' }));
});
}
const spine = put(at, model.addWall({ ...spineWall, height: STOREY, origin: [SPINE.x + SPINE.width, WALL, 0] }));
put(at, model.addDoor({ wallLocalId: spine, width: 4 * CO.x + 10, height: 28 * CO.z, offsetAlongWall: 4250, offsetFromFloor: 0, materialName: 'Timber door' }));
// The stair to the next floor: one straight flight along the spine wall.
if (at < storeys - 1) {
const flight = { width: STAIR.width, riserHeight: STOREY / STAIR.risers, treadLength: STAIR.going, numberOfRisers: STAIR.risers, axisX: Y, axisZ: Z, materialName: MATERIAL.stair };
put(at, model.addStair({ name: 'Stair', predefinedType: 'STRAIGHT_RUN_STAIR', flights: [{ ...flight, origin: [SPINE.x + SPINE.width + STAIR.width, STAIR.y, 0] }], materialName: MATERIAL.stair }));
}
}
return { level, hidden, openings };
}
// ---- display only: a frame, glass and a sill in each opening. The model has the door or the window itself.
function dressing(openings: Opening[], owned: Body[]) {
const frames: Body[] = [], panes: Body[] = [], sills: Body[] = [], doors: Body[] = [];
// A box in the frame of a wall: u along it, v from the outside face inward, z up.
const piece = (side: Side, u0: number, u1: number, v0: number, v1: number, z0: number, z1: number): Body => {
const mid: P3 = side === 'west' ? [(v0 + v1) / 2, (u0 + u1) / 2, (z0 + z1) / 2] : [(u0 + u1) / 2, side === 'south' ? (v0 + v1) / 2 : PLAN.y - (v0 + v1) / 2, (z0 + z1) / 2];
const made = side === 'west' ? box(v1 - v0, u1 - u0, z1 - z0, { at: mid }) : box(u1 - u0, v1 - v0, z1 - z0, { at: mid });
owned.push(made);
return made;
};
for (const o of openings) {
const z0 = o.level * STOREY + o.sill, z1 = z0 + o.height, u0 = o.at, u1 = o.at + o.width, m = 50;
const bottom = o.door ? z0 : z0 + m;
if (!o.door) sills.push(piece(o.side, u0, u1, -40, 30, z0, z0 + m), piece(o.side, u0, u1, 30, 100, z0, z0 + m));
frames.push(piece(o.side, u0, u0 + m, 30, 100, bottom, z1), piece(o.side, u1 - m, u1, 30, 100, bottom, z1), piece(o.side, u0 + m, u1 - m, 30, 100, z1 - m, z1));
// One light for each 700 mm of width, with a mullion between two lights.
const lights = o.door && o.width < 1000 ? 1 : Math.max(1, Math.round(o.width / 700)), pitch = (o.width - m) / lights;
for (let i = 0; i < lights; i++) {
const a = u0 + m + i * pitch, b = a + pitch - m;
if (i > 0) frames.push(piece(o.side, a - m, a, 30, 100, bottom, z1 - m));
(lights === 1 && o.door ? doors : panes).push(piece(o.side, a, b, 50, lights === 1 && o.door ? 94 : 74, bottom, z1 - m));
}
}
const parts: [Body[], string][] = [[frames, '#f5f2ea'], [panes, '#9fc3d4'], [sills, '#e3dfd3'], [doors, '#12b5b0']];
return parts.filter(([list]) => list.length > 0).map(([list, tint]) => color(compound(list), tint));
}Functions used
placedSolids toIfc box compound measureVolume unwrap color present