Show building storeys
List the storeys of one or more models as one set of floors, show a floor on its own and fit the view to it, toggle floors with checkboxes, and show or hide the objects that are in no storey.
A storey picker is the first control many viewer pages get. BIM.works lists the storeys of the models you load as one set of floors, merged across the models, and the ObjectStateManager shows and hides them.
Live demo#
The architectural and the electrical model of S1 are loaded together; each floor is one row with the storey objects of both models (the Models column). Click a name to show that floor alone and fit the view to it; untick boxes to hide floors. The last row holds the objects that are in no storey. Show all restores everything.
Before you start#
You have a viewer with one or more models loaded (Embed the viewer) and their Vids. The credential needs query:run.
Steps#
// The viewer, modelManager and objectStateManager of the embed example, with one or more models
// loaded; versionUuids are their Vids
const listed = await client.bim.listBuildingStoreys(versionUuids);
// One entry per floor over all models, highest first; "[No BS]" has no storey objects
const storeys = listed.buildingStoreys.sort((a, b) => b.elevation - a.elevation);
const list = document.createElement("div");
document.body.prepend(list);
for (const storey of storeys) {
const storeyQids = storey.buildingStoreys.map((buildingStorey) => buildingStorey.qid);
const noStorey = storeyQids.length == 0;
// A checkbox shows and hides the storey, keeping the others as they are
const label = document.createElement("label");
const checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.checked = true;
checkbox.addEventListener("change", () => {
if (noStorey) {
objectStateManager.setNoBuildingStoreysVisibility(checkbox.checked);
} else {
objectStateManager.setBuildingStoreysVisibility(storeyQids, checkbox.checked);
}
});
label.append(checkbox, storey.name);
// The name shows the storey alone and fits the view to it
if (!noStorey) {
label.addEventListener("dblclick", async () => {
await objectStateManager.setBuildingStoreysVisibleExclusive(storeyQids);
await objectStateManager.viewFit(modelManager.getObjectQidsForBuildingStoreyQids(storeyQids, false), {animate: true});
});
}
list.appendChild(label);
}
A checkbox per storey; a double click on a name shows that storey alone.
-
List the storeys.
client.bim.listBuildingStoreys(versionUuids)answers{buildingStoreys: [...]}, one entry per floor over all the models you pass. Storeys of different models are the same floor when their GlobalId, their name or their elevation match; the entry then joins their names with a comma.Field What nameThe storey's name, or the joined names. elevationThe Elevationattribute, in the length unit of the model.floorThe floor number BIM.works computed by elevation: 0 for the ground floor, negative below it. buildingStoreys[{qid, oid}]: the storey object in each model that has this floor.description,longnameThe storey's attributes. An entry named
[No BS]with nobuildingStoreyscollects the objects that are contained in no storey. -
Show one floor.
setBuildingStoreysVisibleExclusive(storeyQids)shows the objects of those storeys and nothing else; the second argument,trueby default, leaves the openings out.modelManager.getObjectQidsForBuildingStoreyQids(storeyQids, false)gives the floor's objects to fit the view to. -
Toggle floors.
setBuildingStoreysVisibility(storeyQids, visible)shows or hides floors and leaves the rest as it is;setNoBuildingStoreysVisibility(visible)does the same for the objects in no storey. -
Show everything again with
objectStateManager.resetAll()(Hide and isolate).
In BQL the storey of an object is buildingStorey, so GET qid WHERE buildingStorey.attribute.Name = "Erdgeschoss" selects a floor's objects in a query (Building storeys).
Check#
The list has one row per floor, also with two models loaded, and the floor you click is the only one left in the viewer.