---
title: Switch between models
summary: Load several models once and switch between them — show one at a time, highlight one with the others grey, or swap the loaded model for another — without reloading.
order: 15
languages: [javascript]
terms: [model-manager, object-state-manager, version, vid]
see-also: [how-to/viewer3d/embed-the-viewer, how-to/viewer3d/select-and-colour-objects, how-to/models/list-the-tree]
---

# Switch between models

Discipline models are loaded together and looked at one at a time. The [[term:model-manager|ModelManager]] keeps every loaded model and can hide and show whole models; the [[term:object-state-manager|ObjectStateManager]] colours them.

## Live demo

```demo
name: switch-models
title: One model at a time
models: s1, s1-electrical, schependomlaan
height: 520
notes: |
  Both S1 models are loaded once. **Model** picks one; **Show only** hides the other, **Highlight** keeps it in translucent grey. The last button unloads the electrical model and loads another one in its place.
```

## Before you start

You have a viewer ([[page:how-to/viewer3d/embed-the-viewer]]) and the [[term:vid|Vids]] of the models; [[page:how-to/models/list-the-tree]] finds them in a folder.

## Steps

```example
name: viewer-switch-models
code: javascript/viewer-switch-models.js
notes: Four ways to switch; a page usually needs one or two of them.
highlight: 6,10-11,25,38
```

1. **Load them once.** `addModels` takes complete versions: a listing gives summaries, so `getNodeVersion` each Vid first.
2. **Show one.** `modelManager.hideModels(vids)` and `showModels(vids)` hide and show whole loaded models; nothing is reloaded. `viewer.setModelVisible(vid, visible)` does the same for one viewer only.
3. **Or highlight one.** Colour the objects of the other models grey and translucent with `changeColor` and give the chosen one its own colours back with `resetColor`. `modelManager.getModel(vid).qids` are the objects of a model that have geometry.
4. **Or swap.** To keep one model in memory at a time, `modelManager.setModels([version])` unloads every model that is not in the list and loads the ones that are not loaded yet; `removeModels` and `addModels` do the same in two steps.

## Check

Switching between loaded models is instant; the network panel of the browser shows no geometry download until a model is swapped in.
