---
title: Quantity takeoff
summary: Pick objects from what the model holds, or describe them in one sentence; see each measured value in 3D and the total beside it.
order: 30
layout: wide
languages: [javascript]
terms: [viewer, annotation, qid, calculated-value, quantity-set, pset, classification, object-state-manager, bql]
see-also: [how-to/query/text-to-action, how-to/query/use-query-parameters, how-to/viewer3d/annotations, how-to/viewer3d/select-and-colour-objects, reference/bql/meta]
---

# Quantity takeoff

*How many square metres of external wall?* Every choice below is offered from the S1 model itself, and the answer is drawn in the 3D [[term:viewer|viewer]] and listed beside it.

```demo
name: quantity-takeoff
title: Quantity takeoff
models: s1
height: 820
needs: Uses the demo [[term:api-token|API token]] of your [[term:account|account]]: sign in to BIM.works once in this browser. *Describe it* also needs the AI feature, and is dimmed without it.
```

## Try it

1. **Pick the class.** Type `wall`, `slab` or `door` in *IFC class*: only the classes the model has are listed, with their counts (*Wall* includes the standard-case walls). The objects light up; the rest is dimmed and only there for reference: it cannot be hovered or clicked, and it hides none of the values.
2. **Narrow it down.** *PredefinedType*, *+ Property* (then its value) and *+ Classification* (then its code) list only what the objects selected so far carry, each with a count. A filter is a chip; × takes it away.
3. **Or say it.** *Describe it* turns one sentence, *Net surface of the external walls*, into the same selection and picks the quantity it names, listing the calls it made.
4. **Pick the quantity.** *Add up* lists the objects' calculated quantities first, then the model's own quantity sets.
5. **Check it in 3D.** Each object you can see carries its value; from further than 30 m it is a dot, so zoom in to read the values. Calculated quantities also draw the face or line they were measured on. Hover a value or a dot for the object's card.
6. **Correct it by hand.** × in the table, or *Take it out* on a card, removes a line (*Taken out* restores it). *+ Add objects*, then click objects in the model to add them in green. Changes survive another quantity or filter; another class or sentence starts clean.
7. **Use it.** Hover a row to see its object in magenta x-ray, through whatever is in front of it, while the values step aside; click it to fly there. Sort by a column, download the lines as *CSV*.

## How the lists know what the model holds

Every list is a grouped [[term:bql|BQL]] query on the objects selected so far, so it can only offer what is there:

| List | Query |
|---|---|
| IFC class | `GET type, niceType, COUNT(qid) WHERE type IN (IFCELEMENT, IFCSPACE) AND type != IFCFEATUREELEMENT GROUP BY type, niceType` |
| PredefinedType | `GET attribute.PredefinedType, COUNT(qid) WHERE <selection> GROUP BY attribute.PredefinedType` |
| Properties | `GET property.meta, COUNT(qid) WHERE <selection> GROUP BY property.meta`, the names without their values ([[page:reference/bql/meta]]) |
| A property's values | `GET property."Pset_WallCommon"."IsExternal".value, COUNT(qid) WHERE <selection> GROUP BY …` |
| Classification systems | `GET COLLECT(DISTINCT classification.system.name) WHERE <selection>` |
| A system's codes | `GET classification[system.name = "NL/SfB (4 cijfers)"].identity, ….name, COUNT(qid) WHERE <selection> GROUP BY …` |
| Quantities | `GET quantity.meta, COUNT(qid) … GROUP BY quantity.meta` and the same for `calculated.meta` |

The selection is a condition with a parameter for every value picked, `type = IFCWALL AND property."Pset_WallCommon"."IsExternal" = $p1`, bound by the server ([[page:how-to/query/use-query-parameters]]): a value with quotes in it, or a code with dots, never has to be written into the query. The measurement is one more query, `GET qid, attribute.Name, buildingStorey.attribute.Name, calculated.quantity.netSurface, calculated.quantity.netSurface.figure WHERE <selection> USING AREA_UNIT = m2 …`, which gives every line its value in one unit and the figure it was measured on.

## One sentence, with the calls that exist

*Describe it* uses no call made for this demo. [[page:how-to/query/text-to-action|TextToAction]] turns the sentence into a BQL query; when its answer is not valid BQL, the demo asks once more with the error in the question, which the language model usually repairs. The server's own parser and writer then reduce that query to its condition: `ParseQuery` gives its syntax tree, the demo keeps the tree's `where` and puts `GET qid` in front, and `AstToBql` writes it back as text. From there the sentence's condition is a selection like the filters' one, and the quantity is the one whose words the sentence uses (*net surface*, *floor area*), else the usual one of the dimension it asks for (*volume*: net volume), else an area.

## What stays where

The takeoff lives in this page's memory. An integration keeps its takeoffs in its own database, with each line's GlobalId rather than its [[term:qid|Qid]] (a Qid belongs to one version of a model), and runs the same queries on the next version: the GlobalIds taken out or added by hand are the takeoff's own, the rest is the selection's condition, run again.

## How it is built

One JavaScript module per part, in `BimRepository/www/docs-runtime/demos/takeoff/` of the BIM.works sources, on the public packages.

| What | How | Where it is explained |
|---|---|---|
| The 3D view | One `Viewer3d` with its [[term:model-manager|ModelManager]] and [[term:object-state-manager|ObjectStateManager]], the S1 model loaded with the default settings. | [[page:how-to/viewer3d/embed-the-viewer]] |
| The lists and the measurement | `client.bim.query(models, bql, false, false, parameters)`: the grouped queries above and the measurement, with the picked values as parameters. | [[page:how-to/query/run-a-bql-query]] |
| The fields | An autocomplete of the page's own (`combobox.js`): the input keeps the focus, the arrow keys move through the options, Enter picks one; a filter is only offered from the options. | — |
| The sentence | `POST /openapi/ai/TextToAction` with `language: "BQL"`, then `ParseQuery` and `AstToBql` for its condition. | [[page:how-to/query/text-to-action]] |
| Highlighted and dimmed | `objectStateManager.changeColorMulti` with a `ColorChangeMap`: the lines in blue or green, everything else in a faint grey at 2% opacity per surface. `viewer.setWireframeVisibility` suppresses the reference objects' edges so dense outlines do not veil the takeoff; their default edges return when they join it, or *Dim the rest* is off (`resetColor` restores their colours too). Spaces, hidden by default, are shown when they are in the takeoff. | [[page:how-to/viewer3d/select-and-colour-objects]] |
| Reference objects | `objectStateManager.setPickableSet(<the takeoff's objects>)` on a manager made with `{pickability: true}`: the rest takes no hover or click, and, because annotation occlusion reads the picking pass, which draws pickable objects only, only the takeoff's own objects can hide a value. Floor slabs behind the dimmed façade keep theirs (187 of 573 shown, against none). While *+ Add objects* is on, everything is pickable. | [[page:how-to/viewer3d/annotations#occlusion]] |
| The measured faces | `viewer.figures.add(key, entries)`: the figures of every line in one layer, a line taken out set to the `excluded` state, which is not drawn. | [[page:reference/bql/calculated-values]] |
| The values in 3D | An annotation layer with a template of its own (`template.js`, `defineTemplate` with the `AnnotationTemplateKit` card), one row per line on the object's Qid, `clustering: false`, `dotBeyondMm: 30000` and `occlusion: "hide"`; `onAction` gets the card's *Zoom to it* and *Take it out*, `expand(qid, {pin: true})` opens a card from the table. | [[page:how-to/viewer3d/annotations]] |
| Adding by clicking | `viewer.setClickHandler` takes the click instead of selecting, `viewer.pick(x, y)` gives the object, and one query with `WHERE qid IN $sel` measures it. | [[page:how-to/viewer3d/measure]] |
| Table and model together | A row's click selects its object (`setToSelectionSet`) and flies to it: `objectStateManager.viewFit([qid], {animate: true, animationTimeMs, viewDirection})`, the direction keeping the camera's height angle and turning only about the vertical, towards the measured face (`figureLayer.viewDirectionOf`), so the camera orbits the building instead of swinging over it; the card opens once it has landed. An object selected in the model marks its row through a selection listener (`addSelectionListener`). | [[page:how-to/viewer3d/select-and-colour-objects]] |
| The hovered row in x-ray | `objectStateManager.setXRaySet([qid])` while a row is hovered or focused, `clearXRaySet()` when it is left; `viewer.setXRayVisualization` draws it in magenta, apart from the takeoff's blue and green and the viewer's orange selection, and the value layer's `setVisible(false)` keeps the values off it meanwhile. | [[page:how-to/viewer3d/xray-set]] |
