Tutorial·Learn BQL by doing

Your first query

Select objects by IFC type with GET and WHERE, read their attributes, and limit the result.

A BQL statement has two halves. GET lists the features you want in the result; WHERE says which objects to take them from. Run this against Schependomlaan:

BQL#
GET qid, type, attribute.Name WHERE type = IFCDOOR

You get one row per door. qid is the object's identifier in BIM.works (the Qid, a version UUID and an object id joined by a hyphen), type is its IFC class, and attribute.Name is the value of the IFC Name attribute. Every IFC attribute is reachable the same way: attribute.GlobalId, attribute.Description, attribute.LongName on spaces, attribute.Elevation on storeys. Attribute names are case-sensitive and spelled as in the IFC schema; the editor warns when it does not know one. The full list of what GET accepts is in GET, attributes in Attributes.

Types include their subtypes#

type = IFCWALL matches 934 objects in the demo model, although only 652 of them are literally IfcWall: the other 282 are IfcWallStandardCase, a subtype. Type matching follows the IFC inheritance tree, so type = IFCBUILDINGELEMENT matches every wall, slab, door, window and beam at once, and type = IFCPRODUCT matches everything with a place in the building. When you mean the exact class and nothing below it, add NI (no inheritance):

BQL#
GET qid, attribute.Name WHERE type NI = IFCWALL

Two more spellings of the same idea are type IN (IFCDOOR, IFCWINDOW) and type != IFCSPACE; see Types. niceType is the class name written the way people write it (IfcWallStandardCase instead of IFCWALLSTANDARDCASE), handy for output.

What if there is no WHERE?#

Leave the WHERE out and you get every object of every model queried, which is rarely what you want but sometimes exactly right (GET qid, type is the quickest inventory of a model). The reverse also exists: a query that is only a condition, type = IFCSPACE, returns the matching objects with their qid. The viewer uses that form to resolve selections; in this course we always write GET, so the result shape is explicit. WHERE on its own, without GET, is a syntax error.

Keeping the result small#

LIMIT cuts the result to the first n rows, OFFSET skips rows before that. Without an ORDER BY (a later lesson) the order is the model's own order, which is stable for one version but carries no meaning.

BQL#
GET qid, attribute.Name WHERE type = IFCWINDOW LIMIT 10

Your turn#

Four rounds. Edit the starter query until the result is what the goal asks for, then press Run.

GoalDemo model · Schependomlaan
List every space in the model with its name.
GET qid
Editing and checking need JavaScript; the solution is below, and every query runs in the app's Actions tree too.
Hints
  1. Spaces are IfcSpace objects; IFC class names are uppercase in BQL.
  2. The name is the IFC attribute Name: attribute.Name.
  3. A GET list is separated by commas, and the condition follows in WHERE.
Show solution
GET qid, attribute.Name WHERE type = IFCSPACE
Also accepted
GET attribute.Name, qid WHERE type = IFCSPACE
GET qid, attribute.Name AS Name WHERE type = IFCSPACE
GoalDemo model · Schependomlaan
List every door with its name and its IFC class — the type feature itself, not niceType.
GET qid, attribute.Name WHERE type = IFCSPACE
Editing and checking need JavaScript; the solution is below, and every query runs in the app's Actions tree too.
Hints
  1. Only the type in the WHERE has to change.
  2. The class of an object is the feature named type; it can be selected like any other feature.
Show solution
GET qid, type, attribute.Name WHERE type = IFCDOOR
Also accepted
GET qid, attribute.Name, type WHERE type = IFCDOOR
GoalDemo model · Schependomlaan
List the walls that are exactly IfcWall (not IfcWallStandardCase), with their readable class name and their name.
GET qid, attribute.Name WHERE type = IFCWALL
Editing and checking need JavaScript; the solution is below, and every query runs in the app's Actions tree too.
Hints
  1. type = IFCWALL also matches the subtype IfcWallStandardCase.
  2. NI after type switches inheritance off.
  3. niceType is the readable class name.
Show solution
GET qid, niceType, attribute.Name WHERE type NI = IFCWALL
Also accepted
GET qid, attribute.Name, niceType WHERE type NI = IFCWALL
GoalDemo model · Schependomlaan
List the GlobalId and the name of at most ten windows.
GET qid, attribute.Name WHERE type = IFCWINDOW
Editing and checking need JavaScript; the solution is below, and every query runs in the app's Actions tree too.
Hints
  1. GlobalId is an IFC attribute like Name.
  2. LIMIT goes at the end of the statement.
Show solution
GET qid, attribute.GlobalId, attribute.Name WHERE type = IFCWINDOW LIMIT 10
Also accepted
GET qid, attribute.GlobalId, attribute.Name WHERE type = IFCWINDOW LIMIT 10 OFFSET 0

You can now#

  • Write a GET … WHERE … statement and read the rows it returns.
  • Select objects by IFC class, with or without their subtypes.
  • Read any IFC attribute of the selected objects.
  • Cap a result with LIMIT.

Next: Filtering with WHERE, where the condition becomes more than one type.