Reference·Python SDK · bimworksPython

ModelApi

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

Python SDK · bimworks · class · 12 methods

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

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

MethodOperationDescription
add_model_with_urlAddModelWithUrlAdd a new model by providing a URL
augment_bcfAugmentBcfAdd snapshots to a BCF
downloadDownloadDownload the model of the given Version UUID, as uploaded or as IFC or ifcXML.
download_ifc_xmlDownloadIfcXmlDownload the model of the given Version UUID serialized as ifcXML (deprecated, use Download with format ifcxml)
export_geometryExportGeometryThe geometry of models as glTF
export_vector_svgExportVectorSvgExport an orthographic vector drawing (SVG) of a model
get_checkinGetCheckinThe status of a checkin
get_validation_reportGetValidationReportWhy a model is invalid, or why its checkin failed
lookup_model_hashesLookupModelHashesWhich files the server has already
renderRenderA PNG image of a model
schema_conversion_reportSchemaConversionReportThe log of a schema conversion
upload_modelUploadModelUpload a single model using multipart/form-data

add_model_with_url#

Python#
def add_model_with_url(self, add_model_with_url_request: AddModelWithUrlRequest) -> 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
add_model_with_url_requestAddModelWithUrlRequestrequiredThe request: its properties are those of the model, its JSON that of AddModelWithUrl's request body.

Returns#

ModelVersion — Upload was successful

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.AddModelWithUrlRequest.from_json(r"""
{
  "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
result = bimworks.ModelApi(client).add_model_with_url(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

augment_bcf#

Python#
def augment_bcf(self, bcf: bytes, version_uuid: UUID, width: Optional[int] = None, height: Optional[int] = None) -> bytes

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
bcfbytesrequiredThe file. The BCF 2.1 file
version_uuidUUIDrequired
widthintoptionalThe snapshots' width in pixels, 300 when absent
heightintoptionalThe snapshots' height in pixels, 300 when absent

Returns#

bytes — The BCF with the snapshots

Example#

Python#
import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
bcf = "issues.bcf"
version_uuid = "<version uuid of the first demo model>"

# 3. The call
result = bimworks.ModelApi(client).augment_bcf(bcf=bcf, version_uuid=version_uuid)

# 4. The result
with open("augment-bcf.bcf", "wb") as file:
    file.write(result)

download#

Python#
def download(self, download_request: DownloadRequest) -> bytes

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
download_requestDownloadRequestrequiredThe request: its properties are those of the model, its JSON that of Download's request body.

Returns#

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

Example#

Python#
import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.DownloadRequest.from_json(r"""
{
  "type": "VersionModelIdentifier",
  "uuid": "<version uuid of the first demo model>"
}
""")

# 3. The call
result = bimworks.ModelApi(client).download(request)

# 4. The result
with open("download.ifc", "wb") as file:
    file.write(result)

download_ifc_xml#

Python#
def download_ifc_xml(self, model_identifier: ModelIdentifier) -> bytes

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
model_identifierModelIdentifierrequiredThe request: its properties are those of the model, its JSON that of DownloadIfcXml's request body.

Returns#

bytes — The model serialized as ifcXML

Example#

Python#
import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.ModelIdentifier.from_json(r"""
{
  "type": "VersionModelIdentifier",
  "uuid": "<version uuid of the first demo model>"
}
""")

# 3. The call
result = bimworks.ModelApi(client).download_ifc_xml(request)

# 4. The result
with open("download-ifc-xml.xml", "wb") as file:
    file.write(result)

export_geometry#

Python#
def export_geometry(self, export_geometry_request: ExportGeometryRequest) -> bytes

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
export_geometry_requestExportGeometryRequestrequiredThe request: its properties are those of the model, its JSON that of ExportGeometry's request body.

Returns#

bytes — The file

Example#

Python#
import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.ExportGeometryRequest.from_json(r"""
{
  "models": [
    {
      "type": "UrlModelIdentifier"
    }
  ],
  "query": "",
  "format": "glb",
  "colors": {},
  "only_outside_triangles": false
}
""")

# 3. The call
result = bimworks.ModelApi(client).export_geometry(request)

# 4. The result
with open("export-geometry.glb", "wb") as file:
    file.write(result)

export_vector_svg#

Python#
def export_vector_svg(self, export_vector_svg_request: ExportVectorSvgRequest) -> bytes

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
export_vector_svg_requestExportVectorSvgRequestrequiredThe request: its properties are those of the model, its JSON that of ExportVectorSvg's request body.

Returns#

bytes — The drawing

Example#

Python#
import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.ExportVectorSvgRequest.from_json(r"""
{}
""")

# 3. The call
result = bimworks.ModelApi(client).export_vector_svg(request)

# 4. The result
with open("export-vector-svg.svg", "wb") as file:
    file.write(result)

get_checkin#

Python#
def get_checkin(self, get_checkin_request: GetCheckinRequest) -> 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
get_checkin_requestGetCheckinRequestrequiredThe request: its properties are those of the model, its JSON that of GetCheckin's request body.

Returns#

CheckinStatus — The status

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.GetCheckinRequest.from_json(r"""
{
  "job_uuid": "00000000-0000-0000-0000-000000000000",
  "version_uuid": "<version uuid of the first demo model>",
  "wait_ms": 0
}
""")

# 3. The call
result = bimworks.ModelApi(client).get_checkin(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

get_validation_report#

Python#
def get_validation_report(self, get_validation_report_request: Optional[GetValidationReportRequest] = None) -> 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
get_validation_report_requestGetValidationReportRequestoptionalThe request: its properties are those of the model, its JSON that of GetValidationReport's request body.

Returns#

ValidationReportResult — The report

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.GetValidationReportRequest.from_json(r"""
{
  "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
result = bimworks.ModelApi(client).get_validation_report(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

lookup_model_hashes#

Python#
def lookup_model_hashes(self, lookup_model_hashes_request: LookupModelHashesRequest) -> 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
lookup_model_hashes_requestLookupModelHashesRequestrequiredThe 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#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.LookupModelHashesRequest.from_json(r"""
{
  "models": [
    {
      "size": 1048576,
      "partial_xxh64": 12345678901234567890
    }
  ]
}
""")

# 3. The call
result = bimworks.ModelApi(client).lookup_model_hashes(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

render#

Python#
def render(self, render_request: RenderRequest) -> bytes

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
render_requestRenderRequestrequiredThe request: its properties are those of the model, its JSON that of Render's request body.

Returns#

bytes — The image

Example#

Python#
import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.RenderRequest.from_json(r"""
{
  "model": {
    "type": "UrlModelIdentifier"
  },
  "camera": {
    "position": {
      "x": 0.0,
      "y": 0.0,
      "z": 0.0
    }
  },
  "view": "iso_front_right",
  "size": {}
}
""")

# 3. The call
result = bimworks.ModelApi(client).render(request)

# 4. The result
with open("render.png", "wb") as file:
    file.write(result)

schema_conversion_report#

Python#
def schema_conversion_report(self, schema_conversion_report_request: SchemaConversionReportRequest) -> 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
schema_conversion_report_requestSchemaConversionReportRequestrequiredThe 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#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
request = bimworks.SchemaConversionReportRequest.from_json(r"""
{
  "type": "VersionModelIdentifier",
  "uuid": "<version uuid of the first demo model>",
  "target_schema": "IFC4"
}
""")

# 3. The call
result = bimworks.ModelApi(client).schema_conversion_report(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

upload_model#

Python#
def upload_model(self, file: Optional[bytes] = None, node_uuid: Optional[UUID] = None, filename: Optional[str] = None, filesize: Optional[int] = None, content_type: Optional[str] = None, input_file_type: Optional[str] = None, format_settings: Optional[str] = None, hash: Optional[str] = None, force_reprocessing: Optional[bool] = None, tags: Optional[str] = None, validation_settings: Optional[str] = None, wait_ms: Optional[int] = None, force: Optional[str] = None) -> 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
filebytesoptionalThe file. A single uploaded model
node_uuidUUIDoptionalThe UUID of the Node to which to add the models
filenamestroptionalName of the file
filesizeintoptionalFilesize in bytes
content_typestroptionalThe 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
input_file_typestroptionalThe type of the model (an InputFileType name). When present and not UNKNOWN it wins over the filename extension
format_settingsstroptionalA JSON-encoded PointCloudFormatSettings object (multipart form fields are strings) with per-upload point cloud format options
hashstroptionalInstead 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
force_reprocessingbooloptionalProcess the file again, also when the server has processed the same file before
tagsstroptionalTags of the new Version, comma-separated VersionTag names
validation_settingsstroptionalA JSON-encoded ValidationSettings object
wait_msintoptionalAnswer 202 with the checkin's status when the checkin takes longer than this
forcestroptionalAn UploadForce: NONE, NEW_VERSION or NEW_MODEL

Returns#

ModelVersion — Upload was successful

Example#

Python#
import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
file = "model.ifc"
filename = "model.ifc"

# 3. The call
result = bimworks.ModelApi(client).upload_model(file=file, filename=filename)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))