ReferenceRequires VIRTUAL_FEATURES

BFL

The BIM.works Feature Language — one DEFINE per virtual feature, with a target path, an optional type, scope and LET bindings, and a BQL expression as its body; how virtual features read each other and stored values, LOOKUP and code lists on data files, the decision-table form with its import and export, and how a request applies them.

A virtual feature is a feature that is computed instead of stored: a property, a quantity, an attribute, a classification, a material or a layer that a definition derives from what the model does hold. It is written once and then read through an ordinary BQL path — in GET, WHERE, GROUP BY, aggregates, checks and the features panel — so a query does not repeat the logic, and does not change when the logic does. The grammar builds on BQL (BFL grammar); everything after AS is a BQL expression (Functions and CASE).

BFL#
DEFINE property."BW"."Kind"
AS CASE
	WHEN type = IFCDOOR THEN "door"
	WHEN type = IFCWINDOW THEN "window"
	ELSE "other"
END

With that definition applied, property.BW.Kind behaves like a stored property:

BQL#
GET property.BW.Kind, COUNT(qid) WHERE property.BW.Kind != "other" GROUP BY property.BW.Kind

The definition#

Text#
DEFINE <target> [: <type>] ["description"]
[FOR <condition>]
[LET <name> = <expression>, ...]
AS <expression>
Part Meaning
target The path the feature is read through, see targets.
: type Declares the type of the value: TEXT, NUMBER, BOOLEAN, LENGTH, AREA, VOLUME, MASS, COUNT. A value of another kind is no value for that object. Without it the type follows the body.
description A text in quotes, shown with the definition. The editor's own Description field is usually enough.
FOR The objects the feature exists on, a condition as in WHERE. Outside it the feature has no value.
LET Names a sub-expression. It is referenced as @name in the body and in later bindings.
AS The value: any BQL expression — a feature path, arithmetic, a function, CASE.
BFL#
DEFINE quantity."BW"."Height" : LENGTH
FOR type = IFCDOOR
LET box = calculated.aabb.maxz - calculated.aabb.minz
AS GREATEST(@box, attribute.OverallHeight)

Targets#

Target Read as Values per object
property."Set"."Name" property.Set.Name one
quantity."Set"."Name" quantity.Set.Name one, with a unit
attribute.Name attribute.Name one
classification "System" an entry of classification, in that system entries are added
material an entry of material entries are added
layer an entry of layer entries are added

Set, property, quantity and system names follow the BQL path rules: quote a name with spaces or a reserved word.

A property, a quantity and an attribute are single-valued: the virtual value is the value of the path. When the model also stores a value at that path, the virtual one shadows it; a response then carries the stored value alongside (stored), and the definition itself still reads the stored value through its own path — which is how a definition cleans up a stored feature:

BFL#
DEFINE attribute.Name
AS UPPER(TRIM(attribute.Name))

A classification, a material and a layer are multi-valued: the stored entries stay and the definition adds one. The body gives the entry's identification (or name); REFERENCE(identification, name) gives both.

BFL#
DEFINE classification "Project codes"
AS CASE
	WHEN type = IFCDOOR THEN REFERENCE("31.1", "Doors")
	WHEN type = IFCWINDOW THEN REFERENCE("31.2", "Windows")
END

Building on other virtual features#

A definition reads another virtual feature through its path, like any feature. References are resolved when a definition is saved and when a request is compiled: a cycle is refused, and so is a chain deeper than the server allows (virtual_features.max_depth, 8 by default). A definition that is switched off is still available to the definitions that build on it; it is computed, but not shown.

BFL#
DEFINE property."BW"."Opening"
AS CASE WHEN property.BW.Kind IN ("door", "window") THEN true ELSE false END

Values from other objects#

A body can read the one related object through a path, and summarise a related set with an aggregate over the relation (sub-features#aggregates): the numeric aggregates, COUNT, FIRST — with ORDER BY the arg-min or arg-max — and COLLECT. members goes from a zone, a system or a group to what it groups.

BFL#
DEFINE property."BW"."Storey"
AS buildingStorey.attribute.Name
BFL#
DEFINE quantity."BW"."Smallest space" : AREA
FOR type = IFCBUILDINGSTOREY
AS children(MIN(calculated.quantity.floorArea) WHERE type = IFCSPACE)
BFL#
DEFINE property."BW"."Smallest space name"
FOR type = IFCBUILDINGSTOREY
AS children(FIRST(attribute.Name) WHERE type = IFCSPACE ORDER BY calculated.quantity.floorArea)
BFL#
DEFINE quantity."BW"."Spaces" : COUNT
FOR type = IFCZONE
AS members(COUNT(qid) WHERE type = IFCSPACE)

The conditions inside the parentheses are about the related objects; the object the feature is on is not addressable there.

Several values: CASE ALL and COLLECT#

A classification, a material and a layer can get several entries from one definition. CASE ALL adds a value for every branch whose condition holds — the levels of a hierarchical code — and COLLECT over a relation one per related object. Equal values are one entry. For a property, a quantity or an attribute, which have one value, CASE ALL is refused when the definition is saved.

BFL#
DEFINE classification "Element levels"
AS CASE ALL
	WHEN type IN (IFCDOOR, IFCWINDOW) THEN REFERENCE("A", "Openings")
	WHEN type = IFCDOOR THEN REFERENCE("A10", "Doors")
	WHEN type = IFCWINDOW THEN REFERENCE("A20", "Windows")
END

Data files: LOOKUP and NAMES FROM#

LOOKUP(file, key, keyColumn, valueColumn) translates a value through a table — a CSV or XLSX data file in your actions tree, addressed by its path below your folder. Without keyColumn the key is looked up in the first column: LOOKUP(file, key, valueColumn). The file and the columns are literals and are resolved when the definition is compiled, so a missing file or column is an error at save time, and replacing the file changes the answers of the next request.

BFL#
DEFINE classification "Project NL-SfB" NAMES FROM "codes/nlsfb.csv"
AS COALESCE(
	classification[system.name CONTAINS "SfB"].identification,
	LOOKUP("codes/crosswalk.csv", classification[system.name CONTAINS "Uniclass"].identification, "uniclass", "nlsfb")
)

NAMES FROM names a code list with the columns code and name: every entry gets the name of its code. classification[<field> <comparison>] reads the entries that satisfy the comparison, see classifications#filter.

LOOKUP cannot be used inside a condition (FOR, WHEN): give the lookup a definition of its own and compare that.

The table form#

A definition that is a list of rules — these types with this name get that class — can be kept as a decision table instead of as text. In the editor, + New → Decision table opens a grid: a column per feature that is looked at, a row per rule, the outcome in the last column. A table has no engine of its own. It stands for a DEFINE … AS CASE … END, which is what is compiled, costed and applied, and which View as expression shows at any time; Edit as expression… keeps that text and drops the grid.

Cell Means
(blank) Any value: the column does not take part in the row.
IW*, *IW, *IW* Starts with, ends with, contains — the index-backed forms. Any other use of * and ? is a pattern.
"IW*" The text as it is written.
IfcDoor, IfcWindow One of.
!x, !a, b Not.
< 5 m, >= 2, = 3 m A comparison, with a unit where the feature has one.
5 m .. 12 m Between, both ends included.
true, false A boolean.
+ Has a value.
∅ or - Has no value.

The outcome of a row is a value, =A (the value of column A), or a formula between braces, {CONCAT("EW ", A)}, in which a column id stands for its feature. A row without conditions is the ELSE, and so is the everything else row that closes the grid.

Match decides which row wins when more than one fits:

Match The value is that of
First matching row (FIRST) the first row that fits.
Last matching row (LAST) the last row that fits — how rule lists of other tools read.
Most specific row (BEST) the most specific row that fits: more literal characters, then more cells filled in, so EW-2 wins over EW* wherever it stands. The order is decided when the table is saved, not per object.
Every matching row (ALL) every row that fits — CASE ALL, for a classification, a material or a layer, see several values.

Over the API a table is the table field of AddVirtualFeature, UpdateVirtualFeature and ValidateVirtualFeature (with "form": "TABLE"), and of an inline entry of a request:

JSON#
{"target": {"kind": "PROPERTY", "set": "Project", "name": "Wall class"},
 "scope": "type = IFCWALL",
 "match": "FIRST",
 "columns": [{"id": "A", "feature": "property.*.LoadBearing"}, {"id": "C", "feature": "attribute.Name"}],
 "rows": [{"when": {"A": "true"}, "then": "22.2 core structure"},
          {"when": {"C": "IW*"}, "then": "=C"}],
 "default": "other"}

ValidateVirtualFeature answers with the expression the table stands for under definition, and for a cell that cannot be read with row (counted from 0) and column, which is where the grid puts its mark.

Export and import#

Export… writes the workspace's definitions — all of them, the ones that are switched on, or the selected one with what it builds on — to a .json file, and Import… reads such a file back, here or in another workspace. It is also the format a converter writes, so a set of rules from another tool arrives the same way.

JSON#
{"format": "bimworks-virtual-features", "version": 1,
 "virtual_features": [
   {"name": "Kind", "description": "Doors and windows", "form": "BFL",
    "definition": "DEFINE property.\"BW\".\"Kind\"\nAS CASE WHEN type = IFCDOOR THEN \"door\" ELSE \"other\" END"},
   {"name": "Loud kind", "form": "BFL", "enabled": false,
    "definition": "DEFINE property.\"BW\".\"Loud kind\"\nAS UPPER(property.BW.Kind)"}]}

An entry has a name, a definition — or a table (the table form) — and optionally a description and "enabled": false. The order does not matter.

The definitions of a file build on each other, so a file is saved as one: everything is compiled where it lands, against what is there and against each other, and either all of it is saved or nothing. Before anything is saved the import sheet lists per definition what would happen — new, replaces the one here, skipped, or the error that keeps the file out — and asks one thing, only when the file meets a path that is already defined:

Choice on_conflict A definition whose path is already defined here
Replace them replace becomes the next version of the one here, which keeps its uuid, its history and whether it is on. Importing a regenerated file updates what the previous import made.
Keep both disable is added switched off, because two definitions that are on cannot answer to one path.
Skip them skip is left out.

Over the API: ExportVirtualFeatures (optionally uuids) answers with the envelope, and AddVirtualFeatures takes its virtual_features with on_conflict (default disable), enabled for all new definitions, save_comment for the versions a replacement makes, and dry_run — which saves nothing and reports an error per definition instead of refusing the request. It answers with saved: per definition the uuid, address, action (added, replaced, skipped), enabled, and disabled_because.

Rule files of other tools#

+ New → Table from a rule list / a rules sheet reads a rule file into a table draft (ImportVirtualFeatures): nothing is saved, the draft opens unsaved with the importer's remarks, and what you have looked at you save.

format Reads
json The envelope of ExportVirtualFeatures.
rules-csv A rule list with the columns Element Type, Property, Operator, Value, Action, Output, where And lines join the rule below them and the last rule that fits wins. Becomes a table with match Last.
grid-csv, grid-xlsx A rules sheet: a header row with what each column looks at, a rule per row, the outcome in the last column. match chooses how rows compete, blank: "empty" reads a blank cell as "has no value" instead of "any".

The rule and sheet formats take the name and the target of what they define. A header such as Pset_WallCommon.LoadBearing is turned into a path by a guess, and every guess comes back as a warning to check against where your models keep the value. These two readers follow the published descriptions of such files; they have not been run against files exported by the tools that write them, so treat a first import as a draft in the full sense.

Missing values and errors#

  • An object outside FOR, in no CASE branch, or whose body has no value, has no value for the feature — exactly like an object that lacks a stored feature: a positive comparison does not select it, and !=, NOT IN and = null do.
  • A value that does not conform to the declared type is no value.
  • A definition that does not compile is never applied partially: the request answers with the error for an explicit selection, and leaves the feature out — listed under virtualFeatureIssues — for "enabled".

Cost#

Every definition gets a cost class when it is saved, shown in the editor's status strip:

Class Meaning
Index-backed The body is a CASE, a COALESCE, a constant or a plain path: a condition on the feature is answered from the indices of the conditions and outputs it is made of, at the speed of the hand-written OR query.
Computed per object The body calls a function or does arithmetic. A condition or a GROUP BY that looks at most of a model computes the feature once for the whole model and keeps the result; every query after that reads it. A query about a few objects computes just those.
Crosses relations The body reads other objects through a relation. Kept per model in the same way.

What is kept is a column of values per model and definition. A model never changes and the key covers the definition, what it builds on and its data files, so a column is never out of date — it is only dropped when the server needs the memory (virtual_features.cache_max_bytes, 256 MB by default; 0 switches columns off), and rebuilt when asked for again. Two people with the same definition share one. A workspace with an object filter keeps its own columns, because its values are computed inside the filter.

Applying virtual features to a request#

Query2, QueryCount and TableExport take a virtual_features field. Without it nothing is applied, so existing API clients see no difference; the BIM.works UI always sends "enabled".

Value Applies
"enabled" The enabled definitions of the workspace the request works in (workspaces).
"none" Nothing.
["<uuid>", ...] Exactly these, enabled or not, with what they build on. They have to be part of that workspace's set.
{"apply": "enabled", "include": [...], "exclude": [...], "inline": [{"definition": "DEFINE ..."}]} A combination; inline carries unsaved definitions, for who manages the workspace.

A value that comes from a virtual feature carries virtual, the uuid of its definition, and the response describes the applied definitions once under virtualFeatures (name, kind, address, definition, owner, cost class). In the JavaScript SDK: bim.query(models, query, {virtualFeatures: "enabled"}), or bim.setVirtualFeatures("enabled") for every query of the client; the table rides on the result array as result.virtualFeatures.

Two enabled definitions cannot have the same target, and at most virtual_features.max_enabled_per_owner can be on at once in a workspace.

Workspaces#

Virtual features belong to a workspace. There are no personal definitions beside it: your own definitions are those of your personal workspace. A request applies the set of the workspace it works in — in the BIM.works UI the workspace of the browser tab, over the API the workspace_uuid of the call, else your default (personal) workspace, and for someone who opens a published workspace that workspace. So there is never more than one set at a time, and everyone working in a workspace, and its visitors, gets the same values from the same query.

  • The set is the workspace's effective set: its own enabled definitions plus those of the workspaces above it. Where two claim the same path the nearer workspace wins, so a sub-workspace overrides one definition of its parent and inherits the rest. A workspace definition can build on an inherited one, and LOOKUP files are looked for in the workspace's actions first, then in its parents'.
  • The workspace needs the feature itself: VIRTUAL_FEATURES in the workspace's own feature set — for a personal workspace that is your account's set. What the people in it have does not matter: without it no definition applies there, and the management tasks answer USER_FEATURE_REQUIRED.
  • Who manages the workspace edits its set — its owner, an administrator of its organisation, a superadmin — on the workspace's Virtual features page, or from the definition card of a virtual value. Members see the same page read-only. Every management task works in the call's workspace_uuid.
  • A visitor cannot author. In a workspace session "enabled", "none" and include / exclude of definitions of the effective set are accepted; inline definitions and other uuids are refused.
  • Definitions can stay private. With "Show definitions to visitors" off (SetWorkspaceVirtualFeatureSettings, show_definitions), a visitor still sees which values are virtual, with their name, description and owner, but not the text.
  • Copying between workspaces — from a parent ("Override here") or from another workspace you work in: CopyVirtualFeatures takes uuids and an optional to_workspace_uuid (else the call's workspace), brings along what a definition builds on, and refuses the whole copy when something would not compile where it lands. A copy whose path is already answered arrives switched off. Copies are independent afterwards. Export and import do the same through a file.
  • Who manages a workspace can ask for its set while working in another with {"workspace_uuid": "…", "apply": "enabled"} — which is how the workspace page previews.

Pages#

  • BFL grammarThe Xtext grammar of BFL as shipped in this release.