Units and parameters
Convert units per column with UNIT or per statement with USING, write unit literals in conditions, and bind values at run time with $parameters.
Quantities have units, and models disagree about them: the demo model stores lengths in millimetres and areas in square metres, the next model may be in metres and feet. BQL lets you say which unit you want, in the result and in the condition, and leaves the conversion to the server.
USING for the whole statement#
USING, the last clause of a statement, sets the unit of every value of that dimension in the result:
GET qid, attribute.Name, quantity.*.Height, quantity.*.Length WHERE type = IFCWALL USING LENGTH_UNIT = mThe value in the result is in metres, whatever the model stored, and the row says both: value and unit are what you asked for, original_value and original_unit what the file had — 0.51 m next to 510 mm. A value that is already in the target unit comes back unchanged and without the original_* fields, which is why converting the volumes of this model to m3 changes nothing: the file already stores them in cubic metres. The clauses are LENGTH_UNIT, AREA_UNIT, VOLUME_UNIT, MASS_UNIT and TEMPERATURE_UNIT, in any order, each at most once: USING LENGTH_UNIT = m AREA_UNIT = m2.
UNIT on a column#
UNIT after a single GET item converts that column and ignores USING for it:
GET qid, attribute.Name, calculated.quantity.volume UNIT m3 WHERE type = IFCWALLUNIT belongs to a single feature; an aggregate cannot carry it (SUM(x) UNIT m3 is a syntax error) — convert the whole result with USING instead. It works on any numeric value: quantity.*.NetVolume UNIT m3 and aabb.height UNIT m convert an exported quantity and a bounding-box side the same way.
USING with aggregates#
USING also converts what an aggregate computed, which is the only way to choose the unit of a SUM or an AVG:
GET typeObject.attribute.Name, SUM(quantity.*.NetVolume) AS Volume
WHERE type = IFCWALL GROUP BY typeObject.attribute.Name
USING VOLUME_UNIT = m3Use UNIT for one column and USING for the statement rather than both on the same value. The units are listed in UNIT and USING and parameters.
UNIT, USING and the unit literals in conditions take every unit of the grammar, imperial units and litres included (using#units).
Units in conditions#
A numeric literal in WHERE takes a unit too, and the comparison converts before it compares. quantity.*.Height BETWEEN 2 m AND 3 m and quantity.*.Height BETWEEN 2000 mm AND 3000 mm select the same walls. Both sides of a comparison may be expressions: quantity.*.NetVolume > calculated.quantity.volume * 1.1 compares two features, units resolved on both sides. Give a literal its unit: a number without one is compared as it is, without conversion (unit#literals).
Parameters#
A $name may stand in for any literal: = $x, > $min, IN $values, type IN $types, qid IN $selection, BETWEEN $low AND $high. The value is supplied when the query runs, by the parameter panel of a stored query in the app, or by the parameters object of the query call in the JavaScript SDK and the Java request API:
GET qid, attribute.Name WHERE type IN $types AND attribute.Name CONTAINS $textconst factory = new BimWorksClientFactory("https://bim.works");
const client = await factory.createClientWithApiToken("<your API token>");
const query = "GET qid, attribute.Name WHERE type IN $types AND attribute.Name CONTAINS $text";
const parameters = {
types: ["IFCWALL", "IFCSLAB"],
text: "vloer"
};
// query(models, query, useCache, forceGetQid, parameters)
const results = await client.bim.query(["<version uuid of the first demo model>"], query, false, false, parameters);
console.log(results.length + " objects");
for (const object of results) {
console.log(object.qid + ": " + object.attribute.Name.value);
}
The parameters object maps names to values: a list of class names for type IN $types, a string for CONTAINS $text. The same query runs with different values without being edited, and the values are never spliced into the text, so a user-supplied string cannot change the query. Use query parameters shows the Java form; the .NET SDK, the PHP client and the HTTP Query operation have no parameters field yet.
A query with an unbound parameter is valid but matches nothing for that condition, so a parameter is only useful together with the values: the last round of this lesson declares $text and the page binds it before it runs your query.
Your turn#
GET qid, attribute.Name, quantity.*.Height, quantity.*.Length WHERE type = IFCWALLHints
- USING is the last clause of the statement.
- Both quantities are lengths, so one LENGTH_UNIT clause covers them.
- The model stores millimetres, so the numbers have to change.
Show solution
GET qid, attribute.Name, quantity.*.Height, quantity.*.Length WHERE type = IFCWALL USING LENGTH_UNIT = mGET attribute.Name, qid, quantity.*.Length, quantity.*.Height WHERE type = IFCWALL USING LENGTH_UNIT = mRead one converted leaf in the JSON: value and unit are the metres you asked for, original_value and original_unit the millimetres the file stored.
GET qid, attribute.Name, calculated.quantity.volume WHERE type = IFCWALLHints
- UNIT follows the GET item it converts.
- The unit for cubic metres is m3.
Show solution
GET qid, attribute.Name, calculated.quantity.volume UNIT m3 WHERE type = IFCWALLGET qid, calculated.quantity.volume UNIT m3, attribute.Name WHERE type = IFCWALLGET qid, attribute.Name, quantity.*.Height WHERE type = IFCWALLHints
- BETWEEN takes two bounds joined by AND, and each bound may carry a unit.
- The model stores millimetres, so the result needs a conversion of its own.
Show solution
GET qid, attribute.Name, quantity.*.Height WHERE type = IFCWALL AND quantity.*.Height BETWEEN 2 m AND 3 m USING LENGTH_UNIT = mGET qid, attribute.Name, quantity.*.Height WHERE type = IFCWALL AND quantity.*.Height BETWEEN 2000 mm AND 3000 mm USING LENGTH_UNIT = mGET qid, attribute.Name, quantity.*.Height WHERE type = IFCWALL AND quantity.*.Height >= 2 m AND quantity.*.Height <= 3 m USING LENGTH_UNIT = m$text to "kamer" (room).GET qid, attribute.Name, attribute.LongName WHERE type = IFCSPACE AND attribute.LongName CONTAINS "kamer"Hints
- A parameter is a $ followed by its name, in the place of the literal.
- The name matters: this round binds $text.
- Nothing else about the query changes.
Show solution
GET qid, attribute.Name, attribute.LongName WHERE type = IFCSPACE AND attribute.LongName CONTAINS $textGET qid, attribute.LongName, attribute.Name WHERE type = IFCSPACE AND attribute.LongName CONTAINS $textEvery round of this course binds the parameters it declares, so $text arrives with a value. In your own code the values travel next to the query — client.bim.query(models, query, false, false, {text: "kamer"}) in JavaScript — and are inserted into the parsed query, never into its text, so a value from a user can never change what the query does.
A parameter name may not be a word the grammar uses: $name and $level are syntax errors, $text and $storey are fine. A parameter behind a relation (buildingStorey.attribute.Name = $storey) binds like any other.
You can now#
- Convert one column with
UNITand a whole result withUSING. - Write conditions with unit literals and compare features with each other.
- Parameterise a query with
$nameand bind the values from an SDK.
Next: Calculated values, the quantities BIM.works works out from the geometry itself.