---
title: X-ray a set of objects
summary: Put any set of objects in x-ray from code, without selecting them, so the viewer draws them with translucent faces and edges through the walls, floors and ceilings in front of them.
order: 35
since: 3.0
languages: [javascript]
terms: [object-state-manager, qid]
see-also: [how-to/viewer3d/select-and-colour-objects, how-to/viewer3d/hide-and-isolate, how-to/using-bimworks/navigate-the-3d-viewer, how-to/viewer3d/proximity-fade]
---

# X-ray a set of objects

The [[term:object-state-manager|ObjectStateManager]] keeps an **x-ray set**, and the 3D viewer draws the objects in it with translucent faces and edges through whatever hides them. Selection is not involved: selecting, deselecting or clearing the selection leaves the x-ray set alone. That lets a page show where all the columns, ducts or doors are while the user keeps clicking around. This is not *X-ray selection*, the older display option that draws the selection this way ([[page:how-to/using-bimworks/navigate-the-3d-viewer#selection-appearance]]).

## Live demo

```demo
name: xray
title: X-ray without selecting
models: ac11
height: 520
notes: |
  The stairs are x-rayed when the demo starts: you see the stairwell through the façade. Orbit around the building to follow it. The buttons put the columns or the doors in the x-ray set instead, and the colour, opacity, **Faces** and **Edges** controls change how the set is drawn. Click an object to select it: selection works as before and is drawn on top of the x-ray. **Hide them** hides the x-rayed objects. Hidden objects are not x-rayed, but they stay in the set, so they come back x-rayed when you untick it.
```

## Steps

1. **Fill the set.**

   ```example
   name: xray-api
   code: javascript/viewer3d/xray.js
   notes: X-rays the columns with a BQL condition, switches to an orange style and clears the set again.
   ```

   `setXRaySet` takes a BQL condition or a set of [[term:qid|Qids]] and replaces the set. `addToXRaySet`, `removeFromXRaySet` and `clearXRaySet` edit it, and `getXRayQids` and `isXRayed` read it.

2. **Style it.** `viewer.setXRayVisualization(new XRayVisualization(faceColor, edgeColor))` sets the style: a face colour whose alpha is the overlay opacity, an edge colour, and switches for faces and edges. The default is blue, so the x-ray set is easy to tell apart from the green of X-ray selection. To change the current style, edit the object you get from `getXRayVisualization()` (`faceColor`, `color`, `facesEnabled`, `wireframeEnabled`) and pass it back to `setXRayVisualization`.

## How it combines with the other states

- The set lives in the ObjectStateManager, so every 3D viewer connected to it x-rays the same objects. The 2D viewer ignores it.
- The x-ray is an overlay. The objects are still drawn normally underneath, keep their colour and stay pickable the same way as before. The overlay is drawn without depth testing, which is what makes it visible through other objects.
- Visibility wins. Hiding an x-rayed object removes its overlay but keeps it in the set. Section planes clip the overlay like the rest of the model.
- The selection is drawn after the x-ray: a selected object that is also x-rayed shows its selection highlight on top.

## In the app

The app has no control for the x-ray set yet. **View → Selection → X-ray selection** is the older, separate feature that x-rays the selection.

## Limits

Overlapping x-rayed faces add up their opacity, so a dense set looks darker where many objects overlap. Every x-rayed pixel is drawn once more, so x-raying a large part of a big model costs about as much as selecting it with X-ray selection. The overlay cannot be picked: clicking an x-rayed column behind a wall selects the wall.

## Check

After `setXRaySet("type = IFCCOLUMN")` the columns show through the façade; clicking another object selects it and the columns stay x-rayed.
