How-to guide·3D viewerJavaScript

Show DWG drawings

Load a DWG drawing into the 3D viewer next to IFC models, switch between model space and its paper-space layouts, read its layers, and align it under the building.

A DWG drawing uploads like any model, and BIM.works converts it, without a CAD library on the server, into the same geometry the 3D viewer uses for every other model. A 2D drawing becomes a model you can pan, zoom, pick, section and measure against, and a drawing that is aligned to an IFC model lands exactly where the building is. A drawing on its own puts the viewer in 2D mode: seen from the top, a left drag around the press point turns it instead of tilting it, snapping square (viewer.is2dMode(); set2dMode does the same for a 3D model, Show a floor plan). This guide loads one, switches its layouts and places it.

Live demo#

The demo shows the two drawings of the S1 project in your Demo folder, the ground floor plan and the left front façade, one at a time, and adds the S1 building alongside on request. The floor plan is aligned to the IFC model and lies under the building; the façade is an elevation and stands next to it in the same scene.

The S1 drawings, and the IFC model next to themLive demo
Loads the two S1 drawings and the S1 building from the Demo folder of your account with its demo API token: open BIM.works and sign in once in this browser.

Drawing switches between the floor plan (UO100 Plattegrond begane grond) and the façade (UO.200 Voorgevel, linkergevel); the previous drawing is removed from the scene. The Layout dropdown switches between model space and the paper-space sheets of the drawing on the stage, one at a time; a sheet is paper, so it is shown on its own and the building comes back with model space. Add the IFC model alongside loads the building into the same scene and stays while you switch drawings; Fit all frames everything that is loaded.

Before you start#

  • The instance accepts DWG uploads: the type is in its file_types setting, where it is not by default (DWG).
  • The drawing is uploaded (Upload a model) and you have a viewer (Embed the viewer).

Steps#

  1. Load the drawing like any version, through the ModelManager: modelManager.addModels([version]). It loads next to IFC models and point clouds. The viewer switches to the painter render mode for drawings and draws the lines with the colours of the file; the units of the drawing (INSUNITS) are respected.

  2. Read the layouts and layers. The drawing's semantics arrive through a listener once it is loaded:

    JavaScript#
    viewer.addDwgSemanticsListener((versionUuid, semantics) => {
    	console.log(semantics.layouts.map((layout) => layout.name));
    });
    viewer.showDwgLayout(versionUuid, "Sheet 1");   // one sheet at a time
    viewer.hideDwgSheets(versionUuid);              // back to model space

    A drawing shows model space first. showDwgLayout shows one paper-space sheet, including its viewport clipping; hideDwgSheets returns to model space.

  3. Place it under the building. A DWG has no geo reference of its own. It is placed with the model Alignment (MODEL_ALIGNMENT): three matching points in the drawing and the IFC model, or an alignment matrix set through the API (Set the alignment).

In the app#

Upload the .dwg like any file and load it from the tree. The Drawing layouts dropdown in the viewer toolbar appears when a loaded drawing has more than one layout. The Align models window aligns it to a model. Every DWG has a conversion report on the Validation tab of its technical details, which says what was skipped and why.

Limits#

Text is drawn with a single-stroke font, not the SHX or TrueType font of the drawing, and multi-line text is not word-wrapped. Leaders, tolerances, multilines, polyface meshes and thickness extrusions are skipped. Blocks are flattened into the drawing, and a DWG has no object tree, so it cannot be queried with BQL. The 2D viewer does not show DWG files; the sheets are the 3D viewer's layouts. What the reader converts is listed under DWG.

Check#

The drawing appears in the 3D view in the colours of the file; semantics.layouts lists its sheets, and showDwgLayout with one of their names shows that sheet on its own.

Since 3.0