---
title: Quantity check
summary: The model states each wall's net volume, BIM.works measures it on the geometry; see in 3D where the two differ, correct one wall by hand and then all of them with BUL, each correction a new version to switch between.
order: 40
layout: wide
languages: [javascript]
terms: [quantity-set, calculated-value, bul, transaction, version, guid, annotation, viewer]
see-also: [how-to/models/change-a-model-with-bul, reference/bul, reference/bql/where, explanation/calculated-quantities, demos/quantity-takeoff]
---

# Quantity check

Block S1 states the net volume of every wall in its own [[term:quantity-set|quantity set]], `BaseQuantities.NetVolume`. BIM.works measures the same volume on the wall's geometry, `calculated.quantity.netVolume`. For a few hundred walls the two disagree. The demo finds them, writes the measured value into the model for one wall, then for all of them, and keeps every step as a [[term:version|version]] you can go back to.

```demo
name: quantity-check
title: Quantity check
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. Steps 2 and 3 commit new versions of S1 in your Demo folder; *Start over* deletes them.
```

## Try it

1. **See where they differ.** Every object takes the colour of its verdict: red when the model's value and the calculated one are more than 1 % apart, green when they agree, grey (n/a) when the object does not have both. While all storeys are shown, the red ones show through the building.
2. **Click any object.** A card on it shows both values and their difference, and step 2 repeats them. A wall, slab or beam has both values. A window or a door has the calculated one at most: n/a. *Show the largest difference*, or a row of the list, shows the object's storey on its own and flies there. *Storey* in the toolbar picks a storey, *All storeys* brings the building back.
3. **Correct one wall by hand.** With a red wall picked, step 2 shows the [[term:bul|BUL]] statement that writes its calculated value into its quantity set. *Commit as version 2* makes it the next version: it appears under *Versions* marked *New* and on the view, and the wall turns green.
4. **Correct the rest with BUL.** Step 3 shows one statement for every object that still differs, each getting its own calculated value. *Dry run* counts what it would change without writing anything; *Commit as version 3* commits it as a [[term:transaction|transaction]], and nothing differs any more.
5. **Switch between versions.** Click *v1*, *v2* or *v3*: the same view, the same object picked, with that version's values and colours. On an older version the steps point you to the latest, the only one a commit can follow.
6. **Start over** deletes the versions the demo made, so S1 is as it was uploaded again.

## The comparison

The red objects are the ones a single [[term:bql|BQL]] condition selects:

```bql
GET qid, attribute.Name, attribute.GlobalId, quantity.BaseQuantities.NetVolume UNIT m3, calculated.quantity.netVolume UNIT m3
WHERE quantity.BaseQuantities.NetVolume != calculated.quantity.netVolume WITHIN 1 %
```

`WITHIN 1 %` is relative to the right-hand side, the calculated value ([[page:reference/bql/where#within|tolerances in BQL]]), and holds only for objects that have both values. The green ones are `WHERE quantity.BaseQuantities.NetVolume != null AND calculated.quantity.netVolume != null` without the red ones; everything else is n/a. A clicked object is one more query, `WHERE qid IN $sel`, with its [[term:qid|Qid]] as the parameter. How the net volume is measured: [[page:explanation/calculated-quantities#volumes|gross box volume and net solid volume]].

## The statements

Step 2 writes one value to one object, found by its [[term:guid|GlobalId]]: a Qid belongs to one version, the GlobalId stays the same in all of them. For the party wall on the sixteenth floor, which the model gives 2.780 m³ and the geometry 2.406 m³:

```bul
SET quantity.BaseQuantities.NetVolume = 2.4056 m3 WHERE attribute.GlobalId = "1FZA5oSEfz9L8wt43k3Rea"
```

Step 3 corrects every object that still differs in one statement. Its value is not a number but a feature, so every wall gets its own calculated net volume, and its `WHERE` is the condition that makes a wall red:

```bul
SET quantity.BaseQuantities.NetVolume = calculated.quantity.netVolume
WHERE quantity.BaseQuantities.NetVolume != calculated.quantity.netVolume WITHIN 1 %
```

BIM.works reads each wall's value when the statement is committed, from the version it is committed to, converts it to the model's volume unit, and records it per wall with the transaction: a replay writes the same values even if the calculation changes later. An object without a calculated net volume would be left alone; the dry run says how many there are ([[page:reference/bul#set-feature|a feature as the value]]).

## Versions without loading again

`CommitTransaction` returns when the new version is ready. A transaction that changes data keeps every object and its geometry, so the viewer does not load the new version: `modelManager.swapVersion(oldVersion, newVersion)` hands the loaded model over to it, colours, visibility and selection included. Switching between *v1*, *v2* and *v3* is the same swap, back or forward, and takes no download. *Start over* deletes the demo's versions from the latest down: only the last version of a node can be deleted. It never deletes a version it did not make, which it tells by the comment each commit stores.

The commits go to S1 in your Demo folder, whose latest version the other demos load as well.

## How it is built

One JavaScript module per part, in `BimRepository/www/docs-runtime/demos/quantitycheck/` of the BIM.works sources, on the public packages: `check.js` holds the queries, the verdicts and the statements, `template.js` the card, `index.js` the rest.

| What | How | Where it is explained |
|---|---|---|
| The 3D view | One `Viewer3d` with its [[term:model-manager|ModelManager]] and [[term:object-state-manager|ObjectStateManager]], the latest version of S1 loaded with the default settings. | [[page:how-to/viewer3d/embed-the-viewer]] |
| The verdicts | `client.bim.query([vid], bql, false, false, parameters)`: the two queries above per version, kept, as a version never changes. | [[page:how-to/query/run-a-bql-query]] |
| Red, green and grey | `objectStateManager.changeColorMulti` with a `ColorChangeMap` that colours every loaded object; n/a is a grey at 35 % opacity, so the verdicts inside show through the windows. | [[page:how-to/viewer3d/select-and-colour-objects]] |
| Red through the building | `objectStateManager.setXRaySet(<the red objects>)` while all storeys are shown, drawn in red with `viewer.setXRayVisualization`; *Show through* in the toolbar turns it off. | [[page:how-to/viewer3d/xray-set]] |
| A storey on its own | `modelManager.getBuildingStoreys()` for the list, `getBuildingStoreyQids` for its objects, `removeFromVisibleSet` and `addToVisibleSet` for the rest. | [[page:how-to/viewer3d/hide-and-isolate]] |
| The clicked object | `addSelectionListener` on the viewer's own selection; on a click in the model, `viewer.pick(x, y)` gives the point the card stands on. | [[page:how-to/viewer3d/select-and-colour-objects]] |
| The card | An annotation layer with a template of its own (`template.js`, `defineTemplate` with the `AnnotationTemplateKit` card), one row: the picked object, `occlusion: "none"`, at the clicked point or beside the object's middle. | [[page:how-to/viewer3d/annotations#at-a-point|Annotate a model: at a point you click]] |
| Steps 2 and 3 | `POST CommitTransaction` with the statement and a comment, or `dry_run: true` for the counts; step 3's value is a feature ([[page:reference/bul#set-feature|a feature as the value]]). | [[page:how-to/models/change-a-model-with-bul]], [[openapi:CommitTransaction]] |
| The versions | `client.fs.listNodeVersions` for the strip, `modelManager.swapVersion` to show one, `client.fs.deleteNodeVersion` for *Start over*. | [[openapi:ListVersions]], [[openapi:DeleteVersion]] |
