How-to guide·RenderingJavaScript

Export a vector drawing

Export an orthographic view of a model as SVG instead of a raster screenshot — a floor plan cut above a storey, a section or an elevation, with every product its own group — and restrict, colour and label it with BQL and BVL.

A screenshot is pixels. ExportVectorSvg renders the same orthographic view but writes an SVG drawing: filled silhouettes in painter's order with the hidden parts clipped away, the edges of the model from its stored line work rather than from the triangles, and the cut through the building where a plane cuts it. Every product is a <g id="p<oid>"> with its IFC type as class, hidden products are absent, and the output is deterministic: the same request gives the same file.

Live demo#

Vector renderingLive demo
Loads the demo model in this page with the demo API token of your account: open BIM.works and sign in once in this browser.

Pick a view in the View dropdown and press Export as SVG. Every storey is listed twice: its floor plan, cut 1.1 m above the storey's elevation, and a cut exactly at the storey's level. The drawing is shown in the panel as real vector graphics: the mouse wheel zooms in and out around the pointer, the left mouse button drags it, and a double click shows the whole drawing again. The elevations and the roof plan are exports of the whole model. Lines are drawn one screen pixel wide at any zoom; untick 1 px lines to have them scale with the drawing instead. Download saves the file.

Tick Spaces only to see nothing but the rooms (IfcSpace), in the viewer and in the drawing: the export then carries bql: "type = IFCSPACE" — for a floor plan or a horizontal plane narrowed to the rooms the cut passes through (AND aabb.minz < 1100 mm AND aabb.maxz > 1100 mm), because seen from above the rooms of the storey below would otherwise show through the gaps the walls leave — and the Style box is filled with a BVL script that gives every room function its own translucent colour and writes the room's number, name and floor area in it. Export a floor plan, or cut the rooms with the plane below, and edit the script to try other colours and label() rows.

Cut plane in the viewer places a plane in the model, with an icon like a section plane's, and the drawing follows the plane as you drag it. The Plane dropdown chooses its orientation. Horizontal plane starts at the top of the model: drag the icon down through the building and every position is a floor plan. Plane along the X axis starts at the model's largest X, standing upright: drag it back over the X axis and every position is a section, seen from the +X side with everything in front of the plane cut away. Either way the server's answer names the range of cuts that give the very same drawing, so while the plane stays inside that range nothing is requested, a move outside it renders once (at most every 150 ms while you drag), and a position you return to is served from the cache. Changing the dropdown while a plane is in the viewer replaces it. Middle-click the icon to remove the plane.

Before you start#

  • The instance has a local Vulkan render backend, and has not switched off the vector_svg feature (on by default). Without them the export says so instead of returning an empty drawing; Configure the render backend sets up the backend.
  • A login with geometry:read; a styled request (below) needs actions:read as well.

1. Choose the view and the cut#

Field Meaning
view top, bottom, front, back, left or right; or direction: [x, y, z] for any direction.
cut The cut plane in world millimetres along the view direction; geometry on the camera side is removed. A top view cut at a storey's elevation plus 1100 mm is that storey's floor plan.
cut_fraction Or a cut between 0 and 1 through the bulk of the model (0.5 = mid height).
size, jitter The resolution of the visibility pass (2048 by default) and its passes.
hairline true draws every line one screen pixel wide at any zoom (vector-effect="non-scaling-stroke") instead of a width relative to the drawing; the cut lines then carry no extra weight, only their cut class.

The request names the model with a model identifier and answers the drawing as image/svg+xml:

POST/openapi/model/ExportVectorSvgExportVectorSvg reference
Authorization
Bearer <auth token>
Content-Type
application/json
Body
1 2 3 4 5 6
Authorization: Bearer <auth token>
Content-Type: application/json
Accept: */*
curl -X POST "$BIMWORKS_URL/openapi/model/ExportVectorSvg" \
  -H "Authorization: Bearer $BIMWORKS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "model": {"type": "VersionModelIdentifier", "uuid": BIM_WORKS_FIRST_MODEL},
  "view": "top",
  "cut_fraction": 0.5,
  "hairline": true
}' \
  -OJ
Send to see the response

Visibility is real occlusion: every product is decided on the GPU with an id and depth raster, so what is behind a wall is not in the file and what is half hidden is clipped. A cut plane closes the solids it slices: the section of every cut product is a cap in that raster, so what is modelled inside a cut solid — the basement inside the site, a pipe inside a wall — stays hidden behind the cut instead of showing through it.

2. Select, colour and label#

The same BQL and BVL the 3D Tiles export and the viewer take restrict, recolour and label a drawing. They go in styling: bql (or bql_uuid, a stored query) names the objects to draw, bvl (or bvl_uuid) is a BVL script — SHOW/HIDE, COLOR, label(), annotate(text()), VIEWFIT — and parameters binds their $name parameters. Spaces, openings and the spatial containers stay hidden unless the bql or a SHOW names them, exactly as in the viewer.

POST/openapi/model/ExportVectorSvgExportVectorSvg reference
Authorization
Bearer <auth token>
Content-Type
application/json
Body
1 2 3 4 5 6 7 8 9 10
Authorization: Bearer <auth token>
Content-Type: application/json
Accept: */*
curl -X POST "$BIMWORKS_URL/openapi/model/ExportVectorSvg" \
  -H "Authorization: Bearer $BIMWORKS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "model": {"type": "VersionModelIdentifier", "uuid": BIM_WORKS_FIRST_MODEL},
  "view": "top",
  "cut_fraction": 0.5,
  "styling": {
    "bql": "type IN (IFCWALL, IFCWALLSTANDARDCASE, IFCDOOR, IFCWINDOW, IFCCOLUMN, IFCSLAB)",
    "bvl": "if (type = IFCDOOR) { COLOR \"#cc0000\"; } if (type = IFCSPACE) { label(attribute.Name) label(attribute.LongName) label(\"Area\", calculated.quantity.floorArea); }"
  },
  "labels": {"size": 250}
}' \
  -OJ
Send to see the response

A rendered drawing reports its labels as labels (objects, rows, unanchored) in the X-BimWorks-Vector response header, next to cache.

Every label(...) row of an object is drawn as text at the object, one <tspan> per row, in a <g id="l…" class="label hover|annotation IfcType"> group after everything else. HOVER and ANNOTATION are classes, not visibility: a page embedding the drawing hides .label.hover with CSS and shows it on :hover; a print shows everything. A labelled object the script does not show — every space on a plan — is still labelled, on its own outline at the cut, and only where nothing drawn is in front of it. labels.size is the font size in drawing millimetres (250 by default, 2.5 mm on paper at 1:100); labels.fit says what happens when a label is wider than its object: overflow (default), shrink (down to 40 %) or omit.

3. Let the cache work#

A finished drawing is stored with its model version, compressed, and a repeated request for the same view, size and cut plane is served from storage without rendering. The response's cache object says whether it was a HIT or a MISS (over HTTP, in the X-BimWorks-Vector header), and cache: "bypass" or cache: "refresh" in the request skips or replaces the entry. A styled drawing is cached on what the script resolved to — the visible set, the colours, the label rows — never on its text, so two scripts with the same effect share one drawing. A reindex or a deleted version discards its drawings, and a software update of the exporter starts a new generation, so a cached drawing is never stale. A client that accepts zstd content encoding receives the stored bytes as they are.

In a report#

A BRL report viewport with view: plan and a storey renders the plan through the same exporter, styled and filtered by the report's own rules; view: elevation with a direction gives the façades. A vector viewport draws the label() rows of its style: and takes labels: [spaces] and labelSize: (BRL).

A cut plane that follows the viewer#

The demo's live cut plane is a movable plane of the 3D viewer: the export's direction is the plane's normal and its cut the plane's offset, so a horizontal plane gives a floor plan and a plane over the X axis a section (how-to/viewer3d/section-planes#movable-planes).

Limits#

One model per export. Curved surfaces stay polygonal. Spaces, openings and the spatial structure are left out of a plain export. A filter that matches no objects is an error, not an empty file. PDF is only produced by the older plan export, and there is no DXF.

Check#

A top view with cut_fraction: 0.5 returns an SVG whose <g id="p…"> groups carry IFC types as their class, and the same request again reports a cache HIT.

Since 3.0