---
title: Align PDF floor plans
summary: Put PDF floor plans under the building in the 3D viewer — two points clicked on the sheet and in the model, in two viewers side by side, give the alignment of one plan, and the storey elevations place the plans of the other floors.
order: 82
languages: [javascript]
terms: [alignment, version, model-manager, object-state-manager, building-storey]
see-also: [how-to/geo/set-the-alignment, explanation/alignment, how-to/viewer3d/dwg-drawings, how-to/viewer3d/show-a-floor-plan, how-to/viewer3d/building-storeys]
---

# Align PDF floor plans

A PDF uploads like a model, and the 3D viewer shows it as a flat sheet: the page at its own size, in millimetres, at the origin. To put a floor plan under the building, the sheet needs an [[term:alignment]], one matrix stored on its [[term:version]] that scales it to the building's millimetres, turns it and moves it onto its floor. This guide computes that matrix from two points clicked on the sheet and in the model, in two viewers side by side, and then places the plans of the other floors from the storey elevations, without clicking again.

## Live demo

```demo
name: pdf-alignment
title: The plan of floor 1 next to the S1 building
models: s1-pdf-1, s1
height: 600
needs: Uses the S1 floor plans (S1/PDF) and the S1 building in the Demo folder of your account with its demo API token: open BIM.works and sign in once in this browser. The demo stores the alignment of the plans in your Demo folder; **Clear alignments** clears it.
notes: |
  **Pick V1**, then click a corner of the building on the plan and the same corner in the model; **Pick V2** does the same for a second corner, far from the first. **Align** stores the matrix on the plan and loads the plan under floor 01. **Place the other floors** gives the plans of floors 2 to 5 the same matrix, raised to their storeys, and shows the building up to floor 05. **Plan**, **3D** and **Floor** change the right-hand view.
```

## Before you start

- The PDFs are uploaded ([[page:how-to/models/upload-a-model]]) and the building model has building storeys.
- Your client can write the versions: setting an alignment needs `model:write` ([[page:how-to/geo/set-the-alignment]]).
- The page has two elements for the viewers, here `sheet` and `building`, side by side ([[page:how-to/viewer3d/embed-the-viewer]]).

## Steps

```example
name: viewer-align-pdf-floor-plans
code: javascript/viewer-align-pdf-floor-plans.js
notes: A page with a `<div id="sheet">` and a `<div id="building">` side by side, `mat4` from `@bimworks/viewercommon`. The first PDF is the plan of floor 1; the clicks happen in the order of the loop, any viewer first.
highlight: 22,33,36,54-56,59-60,66-69
```

1. **Two viewers.** Each viewer gets a [[term:model-manager|ModelManager]] and an [[term:object-state-manager|ObjectStateManager]] of its own, so the left one loads only the sheet and the right one only the building. Two viewers on one ObjectStateManager show the same models.
2. **Start from the sheet as drawn.** Clear the sheet's alignment before loading it (`setAlignment(vid, null)`): a stored one moves the sheet in the left viewer too, and the clicks would land on the moved sheet.
3. **Pick the points.** `viewer.selectVertex(callback)` waits for one click on a model and calls back with the point, snapped to a nearby vertex or edge. `withoutAlignment` is the point in the model's own millimetres, before its alignment: what `CalculateAlignment` takes. A click on nothing calls back with `null` and keeps waiting; `cancel()` on the returned selector stops it. Pick the second pair far from the first: the rotation and the scale come from the line between the two.
4. **Compute the matrix.** `client.geometry3d.calculateAlignment(point1a, point1b, point2a, point2b)` returns the matrix that maps the `b` points, on the sheet, onto the `a` points, in the model. With two pairs it moves, turns and scales: the scale is the drawing's, 50 for a plan at 1:50, because the sheet is paper in millimetres. The sheet lies at z = 0; give the model's points the height of the floor, so the sheet lies flat on it whatever height the clicked corners have.
5. **Store it and show the sheet.** `setAlignment(vid, matrix)` stores the matrix on the version; a viewer that loads the version afterwards places it with it. A viewer that already has the version loaded keeps the old placement until `viewer.updateModel(vid)` or a reload.
6. **Place the other floors.** Sheets of one set share the paper, the scale and the place of the building on the page, so the plan of another floor needs the same matrix raised by the difference in elevation: `mat4.multiply(out, raise, alignment)` applies the alignment first, then the translation. `listBuildingStoreys` gives each storey's `floor` number and its `elevation` in millimetres ([[page:how-to/viewer3d/building-storeys]]); the drawing number names the floor a sheet shows.

## A sheet on a storey plan

`setBuildingStoreysVisibleExclusive` hides every object outside the storeys, the sheets included: their objects belong to no storey, and a PDF has no [[term:qid|Qids]] to show them again with. To show a storey with its sheet, hide the building's other objects instead and leave the sheets alone:

```javascript
const onStorey = buildingView.modelManager.getObjectQidsForBuildingStoreyQids(storeyQids, false);
const others = [...buildingView.modelManager.getModel(building.uuid).qids].filter((qid) => !onStorey.has(qid));
await buildingView.objectStateManager.removeFromVisibleSet(others);
// one sheet at a time: the others stay loaded
buildingView.viewer.setModelVisible(otherSheet.uuid, false);
```

Hide the slabs (`IFCSLAB`) and ceilings (`IFCCOVERING`) on a plan seen from above, or they cover the sheet ([[page:how-to/viewer3d/show-a-floor-plan]]).

## Limits

- The other floors line up only when their sheets have the layout and the scale of the aligned one. A sheet laid out differently, or at another scale, needs points of its own.
- A sheet is the whole page, title block and margins included, so it reaches well beyond the building.
- Two pairs cannot mirror or skew a sheet. A third pair (`point3a`, `point3b`) gives `CalculateAlignment` a full linear transform ([[page:how-to/geo/set-the-alignment]]).
- The BIM.works UI has the same tool for any two models: *Align models*, with the alignment in the node popup ([[feature:MODEL_ALIGNMENT]], [[page:explanation/alignment]]).

## Check

The sheet's walls lie under the model's walls in the plan of its floor, and in 3D every sheet lies on its own floor. `GetAlignment` on a placed sheet returns the stored matrix, with the floor's elevation plus 20 mm in element 14.
