---
title: From query to IFC
summary: Turn a query into a partial IFC model, download it, and check it in another viewer — plus the other ways a result leaves BIM.works.
order: 90
terms: [bql, qid]
see-also: [tutorials/bql/surveying-a-model, tutorials/bql/final-challenge, reference/bql/output, how-to/models/download-a-model]
---

# From query to IFC

A query does not have to end in a table. The same statement that selects objects can cut them out of the model as a new IFC file, geometry and all: the selection is the filter, and the export writes a valid model containing exactly what the query returned, with the spatial structure (project, site, building, storeys) it needs to be a model rather than a heap of shapes.

## The IFC output

The [[openapi:Query]] operation returns IFC instead of JSON when the request asks for it with `"format": "ifc"`; `"format": "ifcxml"` gives ifcXML. The SDKs wrap the same call:

````code-group
```javascript
const url = await client.ifc.exportIfc([versionUuid], "GET qid WHERE type = IFCDOOR");
window.location = url;
```
```java
String url = client.getIfc().exportIfc(Set.of(versionUuid), "GET qid WHERE type = IFCDOOR");
```
```shell
curl -X POST "$BIM_WORKS_ADDRESS/openapi/ifc/Query" \
  -H "Authorization: Bearer $BIMWORKS_TOKEN" \
  -H "Content-Type: application/json" \
  -o doors.ifc \
  -d '{"models": [{"type": "VersionModelIdentifier", "uuid": "BIM_WORKS_FIRST_MODEL"}], "query": "GET qid WHERE type = IFCDOOR", "format": "ifc", "filename": "doors.ifc"}'
```
````

What the query projects does not matter much for the file — the objects it *selects* do. `GET qid WHERE type = IFCDOOR` and `GET qid, attribute.Name WHERE type = IFCDOOR` produce the same model; the second one only tells you more on screen. The objects keep their own `GlobalId`, so the cut-out can be compared with the original, and the file names itself after the `filename` you pass.

```note
An exported object carries its geometry, its properties and quantities, its materials and its place in the spatial structure. What it does not carry is the objects it *relates* to unless you selected those too: export a door and you get the door, not the wall around it. Select both when the receiver needs the context.
```

## The other ways out

| Form | Call | Good for |
| --- | --- | --- |
| JSON records | [[openapi:Query]], `client.bim.query` | code that reads values |
| Qids only | [[openapi:Query]] `format: qids`, `client.bim.queryQids` | selecting, colouring, hiding in a viewer |
| Count | [[openapi:Query]] `format: count`, `client.bim.queryCount` | a number in a dashboard |
| CSV, XLS, XLSX | [[openapi:Query]] `format: csv` or `xlsx`, `client.bim.tableExport` | a spreadsheet for someone else |
| IFC, ifcXML | this page | a model for another tool |
| BCF | the checks, not a query | issues with viewpoints |

[[bql:output]] describes each of them.

## Your turn

The round below exports what your query selects and gives you the file. Download it, open it in whatever IFC viewer you have — BIMcollab ZOOM, Solibri Anywhere, usBIM.viewer+, the IFC import of your authoring tool, or a fresh upload into BIM.works — and check that what you see is exactly what the goal asked for, with the geometry intact. The download link is a one-time stream: press Run again if you need the file a second time.

```lesson {#lesson-1}
goal: Cut the doors of the ground floor ("00 begane grond") out of the model as an IFC file.
show: ifc
check: objects
starter: |
  GET qid, attribute.Name WHERE type = IFCDOOR
hints: |
  - The storey is a condition on buildingStorey.attribute.Name, as in the relations lesson.
  - The GET list only decides what you see on screen; the WHERE decides what ends up in the file.
solution: |
  GET qid, attribute.Name WHERE type = IFCDOOR AND buildingStorey.attribute.Name = "00 begane grond"
accept: |
  - GET qid WHERE type = IFCDOOR AND buildingStorey.attribute.Name = "00 begane grond"
  - GET qid, attribute.Name WHERE type = IFCDOOR AND buildingStorey.calculated.property.level = 0
```

Open the file you downloaded. You should see the doors of one storey, standing in the air where they stand in the building — no walls, no floors, because you did not select them. Count them: the number in the other viewer must be the number of rows in the round.

```lesson {#lesson-2}
goal: Export a model of the ground floor a fire consultant can use: its spaces and its doors, and nothing of the other storeys.
show: ifc
check: objects
starter: |
  GET qid, type, attribute.Name WHERE type = IFCDOOR AND buildingStorey.attribute.Name = "00 begane grond"
hints: |
  - Two classes in one condition: type IN (…) takes a list.
  - The storey condition holds for both classes, so it stays where it is.
  - A space is an IfcSpace, a door an IfcDoor.
solution: |
  GET qid, type, attribute.Name WHERE type IN (IFCSPACE, IFCDOOR) AND buildingStorey.attribute.Name = "00 begane grond"
accept: |
  - GET qid, type, attribute.Name WHERE (type = IFCSPACE OR type = IFCDOOR) AND buildingStorey.attribute.Name = "00 begane grond"
```

That file is a room book with doors in it: spaces carry their name, their number and their properties, and the doors show where one room leads to the next. It is a fraction of the megabytes of the full model, which is the point of exporting a query rather than the model.

## You can now

- Turn any selection into an IFC or ifcXML file, from the API or an SDK.
- Predict what a cut-out contains, and select the context the receiver needs.
- Choose between JSON, qids, a count, a spreadsheet and a model for a result.

Next: [Final challenge](final-challenge.md), one query that uses everything.
