Reference·TypeScript SDK · @bimworks/sdkTypeScript

ModelApi

TypeScript SDK: the Model operations, 12 methods, each with its parameters, result and a complete example.

TypeScript SDK · @bimworks/sdk · class · 12 methods

Calls related to models, for example to upload or download models

Construct it with the client of the connect step: new ModelApi(client). Each method is one operation of the API part, where it runs on its page.

MethodOperationDescription
addModelWithUrlAddModelWithUrlAdd a new model by providing a URL
augmentBcfAugmentBcfAdd snapshots to a BCF
downloadDownloadDownload the model of the given Version UUID, as uploaded or as IFC or ifcXML.
downloadIfcXmlDownloadIfcXmlDownload the model of the given Version UUID serialized as ifcXML (deprecated, use Download with format ifcxml)
exportGeometryExportGeometryThe geometry of models as glTF
exportVectorSvgExportVectorSvgExport an orthographic vector drawing (SVG) of a model
getCheckinGetCheckinThe status of a checkin
getValidationReportGetValidationReportWhy a model is invalid, or why its checkin failed
lookupModelHashesLookupModelHashesWhich files the server has already
renderRenderA PNG image of a model
schemaConversionReportSchemaConversionReportThe log of a schema conversion
uploadModelUploadModelUpload a single model using multipart/form-data

addModelWithUrl#

TypeScript#
addModelWithUrl(requestParameters: { addModelWithUrlRequest: AddModelWithUrlRequest }): Promise<ModelVersion>

Add a new model by providing a URL. The server fetches the file from url (within its egress policy) and checks it in under node_uuid. The checkin (parsing, geometry, indexing) follows the upload, which is always waited for. Without wait_ms the call answers when the checkin ends, with the new Version, which for a big model can take longer than a gateway waits. With wait_ms it answers the Version when the checkin ends within that many milliseconds, and otherwise 202 with the checkin's status and job_uuid: follow it with GetCheckin. A checkin still running after an hour answers 202 too. A ZIP of models is checked in where it was received and has no job, so it always waits. The same file name in the same folder adds a Version to that model.

OperationAddModelWithUrl · POST /openapi/model/AddModelWithUrl
Scopemodel:upload

Parameters#

NameTypeDescription
addModelWithUrlRequestAddModelWithUrlRequestrequiredThe request: its properties are those of the model, its JSON that of AddModelWithUrl's request body.

Returns#

ModelVersion — Upload was successful

Example#

TypeScript#
import { AddModelWithUrlRequestFromJSON, AuthApi, Configuration, ModelApi, ModelVersionToJSON } from "@bimworks/sdk";

// 1. Connect to BIM.works and log in with your API token
const basePath = "https://bim.works/openapi";
const auth = await new AuthApi(new Configuration({ basePath }))
  .loginWithApiToken({ loginWithApiTokenRequest: { token: "<your API token>" } });
const client = new Configuration({ basePath, accessToken: typeof auth === "string" ? auth : auth.base64 });

// 2. The request
const request = AddModelWithUrlRequestFromJSON({
  "node_uuid": "00000000-0000-0000-0000-000000000000",
  "path": "",
  "filename": "",
  "url": "",
  "input_file_type": "IFC",
  "format_settings": {},
  "force_reprocessing": false,
  "tags": [
    "DEMO"
  ],
  "validation_settings": {},
  "wait_ms": 0,
  "force": "NONE"
});

// 3. The call
const result = await new ModelApi(client).addModelWithUrl({ addModelWithUrlRequest: request });

// 4. The result
console.log(JSON.stringify(ModelVersionToJSON(result), null, 2));

augmentBcf#

TypeScript#
augmentBcf(requestParameters: { bcf: Blob; versionUuid: string; width?: number; height?: number }): Promise<Blob>

Add snapshots to a BCF. Answers the BCF 2.1 file with a PNG snapshot rendered for each viewpoint that has a perspective camera, of the model version_uuid: an integrator keeps its issues and gets BCF with images out of them. Orthogonal viewpoints keep what they had; at most 1000 snapshots are rendered per file.

OperationAugmentBcf · POST /openapi/model/AugmentBcf
Scopegeometry:read

Parameters#

NameTypeDescription
bcfBlobrequiredThe file. The BCF 2.1 file
versionUuidstringrequired
widthnumberoptionalThe snapshots' width in pixels, 300 when absent
heightnumberoptionalThe snapshots' height in pixels, 300 when absent

Returns#

Blob — The BCF with the snapshots

Example#

TypeScript#
import { openAsBlob, writeFileSync } from "node:fs";
import { AuthApi, Configuration, ModelApi } from "@bimworks/sdk";

// 1. Connect to BIM.works and log in with your API token
const basePath = "https://bim.works/openapi";
const auth = await new AuthApi(new Configuration({ basePath }))
  .loginWithApiToken({ loginWithApiTokenRequest: { token: "<your API token>" } });
const client = new Configuration({ basePath, accessToken: typeof auth === "string" ? auth : auth.base64 });

// 2. The request
const request = { bcf: new File([await openAsBlob("issues.bcf")], "issues.bcf"), versionUuid: "<version uuid of the first demo model>" };

// 3. The call
const result = await new ModelApi(client).augmentBcf(request);

// 4. The result
writeFileSync("augment-bcf.bcf", Buffer.from(await result.arrayBuffer()));

download#

TypeScript#
download(requestParameters: { downloadRequest: DownloadRequest }): Promise<Blob>

Download the model of the given Version UUID, as uploaded or as IFC or ifcXML. In case you want to download only a subset of an IFC model, use ifc/query. format chooses what comes back; it wins over the Accept header, which is not read by this operation. original (the default) is the file as it was uploaded, byte for byte; ifc and ifcxml serialize the stored model, so they work for any Version whose model parsed as IFC, whatever its upload encoding. With error_uuid instead of a model identifier the file of a failed upload comes back as it was uploaded.

OperationDownload · POST /openapi/model/Download
Scopemodel:read

Parameters#

NameTypeDescription
downloadRequestDownloadRequestrequiredThe request: its properties are those of the model, its JSON that of Download's request body.

Returns#

Blob — The model file. Without target_schema byte-for-byte as it was uploaded, with target_schema the converted file

Example#

TypeScript#
import { writeFileSync } from "node:fs";
import { AuthApi, Configuration, DownloadRequestFromJSON, ModelApi } from "@bimworks/sdk";

// 1. Connect to BIM.works and log in with your API token
const basePath = "https://bim.works/openapi";
const auth = await new AuthApi(new Configuration({ basePath }))
  .loginWithApiToken({ loginWithApiTokenRequest: { token: "<your API token>" } });
const client = new Configuration({ basePath, accessToken: typeof auth === "string" ? auth : auth.base64 });

// 2. The request
const request = DownloadRequestFromJSON({
  "type": "VersionModelIdentifier",
  "uuid": "<version uuid of the first demo model>"
});

// 3. The call
const result = await new ModelApi(client).download({ downloadRequest: request });

// 4. The result
writeFileSync("download.ifc", Buffer.from(await result.arrayBuffer()));

downloadIfcXml#

TypeScript#
downloadIfcXml(requestParameters: { modelIdentifier: ModelIdentifier }): Promise<Blob>

Download the model of the given Version UUID serialized as ifcXML (deprecated, use Download with format ifcxml). Deprecated, Download with format ifcxml answers the same file; this operation will be removed in a later release. The stored model is converted on the fly, so this works for any Version whose model parsed as IFC, regardless of the encoding it was uploaded in. The ifcXML dialect follows the model's schema, ISO 10303-28 for IFC2X3 and ifcXML4 for IFC4/IFC4X3.

OperationDownloadIfcXml · POST /openapi/model/DownloadIfcXml
Scopemodel:read

Parameters#

NameTypeDescription
modelIdentifierModelIdentifierrequiredThe request: its properties are those of the model, its JSON that of DownloadIfcXml's request body.

Returns#

Blob — The model serialized as ifcXML

Example#

TypeScript#
import { writeFileSync } from "node:fs";
import { AuthApi, Configuration, ModelApi, ModelIdentifierFromJSON } from "@bimworks/sdk";

// 1. Connect to BIM.works and log in with your API token
const basePath = "https://bim.works/openapi";
const auth = await new AuthApi(new Configuration({ basePath }))
  .loginWithApiToken({ loginWithApiTokenRequest: { token: "<your API token>" } });
const client = new Configuration({ basePath, accessToken: typeof auth === "string" ? auth : auth.base64 });

// 2. The request
const request = ModelIdentifierFromJSON({
  "type": "VersionModelIdentifier",
  "uuid": "<version uuid of the first demo model>"
});

// 3. The call
const result = await new ModelApi(client).downloadIfcXml({ modelIdentifier: request });

// 4. The result
writeFileSync("download-ifc-xml.xml", Buffer.from(await result.arrayBuffer()));

exportGeometry#

TypeScript#
exportGeometry(requestParameters: { exportGeometryRequest: ExportGeometryRequest }): Promise<Blob>

The geometry of models as glTF. Exports the triangulated geometry of the objects a BQL condition selects (every product when absent) as one binary glTF file, several models in one file.

OperationExportGeometry · POST /openapi/model/ExportGeometry
Scopegeometry:read

Parameters#

NameTypeDescription
exportGeometryRequestExportGeometryRequestrequiredThe request: its properties are those of the model, its JSON that of ExportGeometry's request body.

Returns#

Blob — The file

Example#

TypeScript#
import { writeFileSync } from "node:fs";
import { AuthApi, Configuration, ExportGeometryRequestFromJSON, ModelApi } from "@bimworks/sdk";

// 1. Connect to BIM.works and log in with your API token
const basePath = "https://bim.works/openapi";
const auth = await new AuthApi(new Configuration({ basePath }))
  .loginWithApiToken({ loginWithApiTokenRequest: { token: "<your API token>" } });
const client = new Configuration({ basePath, accessToken: typeof auth === "string" ? auth : auth.base64 });

// 2. The request
const request = ExportGeometryRequestFromJSON({
  "models": [
    {
      "type": "UrlModelIdentifier"
    }
  ],
  "query": "",
  "format": "glb",
  "colors": {},
  "only_outside_triangles": false
});

// 3. The call
const result = await new ModelApi(client).exportGeometry({ exportGeometryRequest: request });

// 4. The result
writeFileSync("export-geometry.glb", Buffer.from(await result.arrayBuffer()));

exportVectorSvg#

TypeScript#
exportVectorSvg(requestParameters: { exportVectorSvgRequest: ExportVectorSvgRequest }): Promise<Blob>

Export an orthographic vector drawing (SVG) of a model. Renders a floor plan, section or elevation of one model as an SVG drawing with occlusion culling (every product its own group), optionally restricted, recoloured and labelled through BQL and BVL. A request carrying styling also needs the actions:read scope. The response carries the drawing; the cache and labels objects of the task response are returned as the X-BimWorks-Vector header (JSON).

OperationExportVectorSvg · POST /openapi/model/ExportVectorSvg
Scopegeometry:read

Parameters#

NameTypeDescription
exportVectorSvgRequestExportVectorSvgRequestrequiredThe request: its properties are those of the model, its JSON that of ExportVectorSvg's request body.

Returns#

Blob — The drawing

Example#

TypeScript#
import { writeFileSync } from "node:fs";
import { AuthApi, Configuration, ExportVectorSvgRequestFromJSON, ModelApi } from "@bimworks/sdk";

// 1. Connect to BIM.works and log in with your API token
const basePath = "https://bim.works/openapi";
const auth = await new AuthApi(new Configuration({ basePath }))
  .loginWithApiToken({ loginWithApiTokenRequest: { token: "<your API token>" } });
const client = new Configuration({ basePath, accessToken: typeof auth === "string" ? auth : auth.base64 });

// 2. The request
const request = ExportVectorSvgRequestFromJSON({});

// 3. The call
const result = await new ModelApi(client).exportVectorSvg({ exportVectorSvgRequest: request });

// 4. The result
writeFileSync("export-vector-svg.svg", Buffer.from(await result.arrayBuffer()));

getCheckin#

TypeScript#
getCheckin(requestParameters: { getCheckinRequest: GetCheckinRequest }): Promise<CheckinStatus>

The status of a checkin. The status of the checkin of an upload, by the job_uuid an upload answered with 202, or by the version_uuid it made. With wait_ms the call waits that long for the checkin to end (at most 5 minutes). Once it is DONE the answer holds the Version; once it FAILED, the error. Needs read rights on the model. Checkin jobs are kept for 30 days.

OperationGetCheckin · POST /openapi/model/GetCheckin
Scopefs:read

Parameters#

NameTypeDescription
getCheckinRequestGetCheckinRequestrequiredThe request: its properties are those of the model, its JSON that of GetCheckin's request body.

Returns#

CheckinStatus — The status

Example#

TypeScript#
import { AuthApi, CheckinStatusToJSON, Configuration, GetCheckinRequestFromJSON, ModelApi } from "@bimworks/sdk";

// 1. Connect to BIM.works and log in with your API token
const basePath = "https://bim.works/openapi";
const auth = await new AuthApi(new Configuration({ basePath }))
  .loginWithApiToken({ loginWithApiTokenRequest: { token: "<your API token>" } });
const client = new Configuration({ basePath, accessToken: typeof auth === "string" ? auth : auth.base64 });

// 2. The request
const request = GetCheckinRequestFromJSON({
  "job_uuid": "00000000-0000-0000-0000-000000000000",
  "version_uuid": "<version uuid of the first demo model>",
  "wait_ms": 0
});

// 3. The call
const result = await new ModelApi(client).getCheckin({ getCheckinRequest: request });

// 4. The result
console.log(JSON.stringify(CheckinStatusToJSON(result), null, 2));

getValidationReport#

TypeScript#
getValidationReport(requestParameters: { getValidationReportRequest: GetValidationReportRequest }): Promise<ValidationReportResult>

Why a model is invalid, or why its checkin failed. The validation report of a Version (model) or of a failed checkin (error_uuid, from ListNodeErrors): per stage of the checkin (upload, parse, schemaCheck, geometry3d, geometry2d, indexing, ...) its status and its findings, each with its rule, severity and the object it is about. summary_only answers the counts.

OperationGetValidationReport · POST /openapi/model/GetValidationReport
Scopequery:run

Parameters#

NameTypeDescription
getValidationReportRequestGetValidationReportRequestoptionalThe request: its properties are those of the model, its JSON that of GetValidationReport's request body.

Returns#

ValidationReportResult — The report

Example#

TypeScript#
import { AuthApi, Configuration, GetValidationReportRequestFromJSON, ModelApi, ValidationReportResultToJSON } from "@bimworks/sdk";

// 1. Connect to BIM.works and log in with your API token
const basePath = "https://bim.works/openapi";
const auth = await new AuthApi(new Configuration({ basePath }))
  .loginWithApiToken({ loginWithApiTokenRequest: { token: "<your API token>" } });
const client = new Configuration({ basePath, accessToken: typeof auth === "string" ? auth : auth.base64 });

// 2. The request
const request = GetValidationReportRequestFromJSON({
  "model": {
    "type": "UrlModelIdentifier"
  },
  "error_uuid": "00000000-0000-0000-0000-000000000000",
  "summary_only": false,
  "min_severity": "INFO",
  "stage": "",
  "rule": [
    ""
  ],
  "global_id": "",
  "express_id": 0
});

// 3. The call
const result = await new ModelApi(client).getValidationReport({ getValidationReportRequest: request });

// 4. The result
console.log(JSON.stringify(ValidationReportResultToJSON(result), null, 2));

lookupModelHashes#

TypeScript#
lookupModelHashes(requestParameters: { lookupModelHashesRequest: LookupModelHashesRequest }): Promise<LookupModelHashes200Response>

Which files the server has already. For each file, whether the server has processed one with the same content, so its upload can send the hash instead of the bytes (UploadModel). Hash the first 32 KiB and pass that with the size first, which is cheap; for the files that are known, hash the whole file and pass full_xxh64. The answer is in the order asked. max_concurrent_checkins is how many checkins the answering server runs at once: an upload scheduler keeps about that many uploads going.

OperationLookupModelHashes · POST /openapi/model/LookupModelHashes
Scopemodel:upload

Parameters#

NameTypeDescription
lookupModelHashesRequestLookupModelHashesRequestrequiredThe request: its properties are those of the model, its JSON that of LookupModelHashes's request body.

Returns#

LookupModelHashes200Response — Per file whether it is known

Example#

TypeScript#
import { AuthApi, Configuration, LookupModelHashes200ResponseToJSON, LookupModelHashesRequestFromJSON, ModelApi } from "@bimworks/sdk";

// 1. Connect to BIM.works and log in with your API token
const basePath = "https://bim.works/openapi";
const auth = await new AuthApi(new Configuration({ basePath }))
  .loginWithApiToken({ loginWithApiTokenRequest: { token: "<your API token>" } });
const client = new Configuration({ basePath, accessToken: typeof auth === "string" ? auth : auth.base64 });

// 2. The request
const request = LookupModelHashesRequestFromJSON({
  "models": [
    {
      "size": 1048576,
      "partial_xxh64": 12345678901234567890
    }
  ]
});

// 3. The call
const result = await new ModelApi(client).lookupModelHashes({ lookupModelHashesRequest: request });

// 4. The result
console.log(JSON.stringify(LookupModelHashes200ResponseToJSON(result), null, 2));

render#

TypeScript#
render(requestParameters: { renderRequest: RenderRequest }): Promise<Blob>

A PNG image of a model. Renders one model as a PNG. With camera it shows that view; with view one of the named angles, framing the whole model. With neither it answers the screenshot the checkin stored, or else the iso_front_right view. A workspace whose filter limits the objects gets no image of the whole model. Rendering must be enabled on the instance; a host without a GPU renders on the CPU.

OperationRender · POST /openapi/model/Render
Scopegeometry:read

Parameters#

NameTypeDescription
renderRequestRenderRequestrequiredThe request: its properties are those of the model, its JSON that of Render's request body.

Returns#

Blob — The image

Example#

TypeScript#
import { writeFileSync } from "node:fs";
import { AuthApi, Configuration, ModelApi, RenderRequestFromJSON } from "@bimworks/sdk";

// 1. Connect to BIM.works and log in with your API token
const basePath = "https://bim.works/openapi";
const auth = await new AuthApi(new Configuration({ basePath }))
  .loginWithApiToken({ loginWithApiTokenRequest: { token: "<your API token>" } });
const client = new Configuration({ basePath, accessToken: typeof auth === "string" ? auth : auth.base64 });

// 2. The request
const request = RenderRequestFromJSON({
  "model": {
    "type": "UrlModelIdentifier"
  },
  "camera": {
    "position": {
      "x": 0.0,
      "y": 0.0,
      "z": 0.0
    }
  },
  "view": "iso_front_right",
  "size": {}
});

// 3. The call
const result = await new ModelApi(client).render({ renderRequest: request });

// 4. The result
writeFileSync("render.png", Buffer.from(await result.arrayBuffer()));

schemaConversionReport#

TypeScript#
schemaConversionReport(requestParameters: { schemaConversionReportRequest: SchemaConversionReportRequest }): Promise<SchemaConversionReportResponse>

The log of a schema conversion. What a schema conversion lost, added and changed. For a Version that was made by the statement CONVERT SCHEMA pass its identifier; for a converted download pass the identifier of the Version that was downloaded and the target_schema it was converted to. This call reads a log, it converts nothing; a conversion that was never made is not found. The report holds the summary, exact counters per rule and a capped number of findings per rule. Every single loss and addition is in the detail log, which is never capped.

OperationSchemaConversionReport · POST /openapi/model/SchemaConversionReport
Scopemodel:read

Parameters#

NameTypeDescription
schemaConversionReportRequestSchemaConversionReportRequestrequiredThe request: its properties are those of the model, its JSON that of SchemaConversionReport's request body.

Returns#

SchemaConversionReportResponse — The conversion report in the requested format

Example#

TypeScript#
import { AuthApi, Configuration, ModelApi, SchemaConversionReportRequestFromJSON, SchemaConversionReportResponseToJSON } from "@bimworks/sdk";

// 1. Connect to BIM.works and log in with your API token
const basePath = "https://bim.works/openapi";
const auth = await new AuthApi(new Configuration({ basePath }))
  .loginWithApiToken({ loginWithApiTokenRequest: { token: "<your API token>" } });
const client = new Configuration({ basePath, accessToken: typeof auth === "string" ? auth : auth.base64 });

// 2. The request
const request = SchemaConversionReportRequestFromJSON({
  "type": "VersionModelIdentifier",
  "uuid": "<version uuid of the first demo model>",
  "target_schema": "IFC4"
});

// 3. The call
const result = await new ModelApi(client).schemaConversionReport({ schemaConversionReportRequest: request });

// 4. The result
console.log(JSON.stringify(SchemaConversionReportResponseToJSON(result), null, 2));

uploadModel#

TypeScript#
uploadModel(requestParameters: { file?: Blob; nodeUuid?: string; filename?: string; filesize?: number; contentType?: string; inputFileType?: string; formatSettings?: string; hash?: string; forceReprocessing?: boolean; tags?: string; validationSettings?: string; waitMs?: number; force?: string }): Promise<ModelVersion>

Upload a single model using multipart/form-data. Uploads a file into the folder node_uuid (the caller's own root when absent). When LookupModelHashes says the server has the file already, send its hash instead of the file part: no bytes travel. A hash the server cannot use after all answers NO_STREAM (404); send the file then. The checkin (parsing, geometry, indexing) follows the upload, which is always waited for. Without wait_ms the call answers when the checkin ends, with the new Version, which for a big model can take longer than a gateway waits. With wait_ms it answers the Version when the checkin ends within that many milliseconds, and otherwise 202 with the checkin's status and job_uuid: follow it with GetCheckin. A checkin still running after an hour answers 202 too. A ZIP of models is checked in where it was received and has no job, so it always waits. The same file name in the same folder adds a Version to that model.

OperationUploadModel · POST /openapi/model/UploadModel
Scopemodel:upload

Parameters#

NameTypeDescription
fileBloboptionalThe file. A single uploaded model
nodeUuidstringoptionalThe UUID of the Node to which to add the models
filenamestringoptionalName of the file
filesizenumberoptionalFilesize in bytes
contentTypestringoptionalThe content type. When available this information is taken from the Content-Type of the file part. Allowed values are application/ifc, application/xml (for .ifcxml files), application/pdf, application/e57
inputFileTypestringoptionalThe type of the model (an InputFileType name). When present and not UNKNOWN it wins over the filename extension
formatSettingsstringoptionalA JSON-encoded PointCloudFormatSettings object (multipart form fields are strings) with per-upload point cloud format options
hashstringoptionalInstead of the file, its full_xxh64 (see ModelHash) when LookupModelHashes said the server knows it; ignored next to a file, which the server hashes itself. Needs filename
forceReprocessingbooleanoptionalProcess the file again, also when the server has processed the same file before
tagsstringoptionalTags of the new Version, comma-separated VersionTag names
validationSettingsstringoptionalA JSON-encoded ValidationSettings object
waitMsnumberoptionalAnswer 202 with the checkin's status when the checkin takes longer than this
forcestringoptionalAn UploadForce: NONE, NEW_VERSION or NEW_MODEL

Returns#

ModelVersion — Upload was successful

Example#

TypeScript#
import { openAsBlob } from "node:fs";
import { AuthApi, Configuration, ModelApi, ModelVersionToJSON } from "@bimworks/sdk";

// 1. Connect to BIM.works and log in with your API token
const basePath = "https://bim.works/openapi";
const auth = await new AuthApi(new Configuration({ basePath }))
  .loginWithApiToken({ loginWithApiTokenRequest: { token: "<your API token>" } });
const client = new Configuration({ basePath, accessToken: typeof auth === "string" ? auth : auth.base64 });

// 2. The request
const request = { file: new File([await openAsBlob("model.ifc")], "model.ifc"), filename: "model.ifc" };

// 3. The call
const result = await new ModelApi(client).uploadModel(request);

// 4. The result
console.log(JSON.stringify(ModelVersionToJSON(result), null, 2));