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.
| Method | Operation | Description |
|---|---|---|
add_model_with_url | AddModelWithUrl | Add a new model by providing a URL |
augment_bcf | AugmentBcf | Add snapshots to a BCF |
download | Download | Download the model of the given Version UUID, as uploaded or as IFC or ifcXML. |
download_ifc_xml | DownloadIfcXml | Download the model of the given Version UUID serialized as ifcXML (deprecated, use Download with format ifcxml) |
export_geometry | ExportGeometry | The geometry of models as glTF |
export_vector_svg | ExportVectorSvg | Export an orthographic vector drawing (SVG) of a model |
get_checkin | GetCheckin | The status of a checkin |
get_validation_report | GetValidationReport | Why a model is invalid, or why its checkin failed |
lookup_model_hashes | LookupModelHashes | Which files the server has already |
render | Render | A PNG image of a model |
schema_conversion_report | SchemaConversionReport | The log of a schema conversion |
upload_model | UploadModel | Upload a single model using multipart/form-data |
add_model_with_url#
def add_model_with_url(self, add_model_with_url_request: AddModelWithUrlRequest) -> ModelVersionAdd 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.
| Operation | AddModelWithUrl · POST /openapi/model/AddModelWithUrl |
|---|---|
| Scope | model:upload |
Parameters#
| Name | Type | Description |
|---|---|---|
add_model_with_url_request | AddModelWithUrlRequestrequired | The request: its properties are those of the model, its JSON that of AddModelWithUrl's request body. |
Returns#
ModelVersion — Upload was successful
Example#
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#
def augment_bcf(self, bcf: bytes, version_uuid: UUID, width: Optional[int] = None, height: Optional[int] = None) -> bytesAdd 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.
| Operation | AugmentBcf · POST /openapi/model/AugmentBcf |
|---|---|
| Scope | geometry:read |
Parameters#
| Name | Type | Description |
|---|---|---|
bcf | bytesrequired | The file. The BCF 2.1 file |
version_uuid | UUIDrequired | |
width | intoptional | The snapshots' width in pixels, 300 when absent |
height | intoptional | The snapshots' height in pixels, 300 when absent |
Returns#
bytes — The BCF with the snapshots
Example#
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#
def download(self, download_request: DownloadRequest) -> bytesDownload 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.
| Operation | Download · POST /openapi/model/Download |
|---|---|
| Scope | model:read |
Parameters#
| Name | Type | Description |
|---|---|---|
download_request | DownloadRequestrequired | The 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#
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#
def download_ifc_xml(self, model_identifier: ModelIdentifier) -> bytesDownload 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.
| Operation | DownloadIfcXml · POST /openapi/model/DownloadIfcXml |
|---|---|
| Scope | model:read |
Parameters#
| Name | Type | Description |
|---|---|---|
model_identifier | ModelIdentifierrequired | The request: its properties are those of the model, its JSON that of DownloadIfcXml's request body. |
Returns#
bytes — The model serialized as ifcXML
Example#
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#
def export_geometry(self, export_geometry_request: ExportGeometryRequest) -> bytesThe 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.
| Operation | ExportGeometry · POST /openapi/model/ExportGeometry |
|---|---|
| Scope | geometry:read |
Parameters#
| Name | Type | Description |
|---|---|---|
export_geometry_request | ExportGeometryRequestrequired | The request: its properties are those of the model, its JSON that of ExportGeometry's request body. |
Returns#
bytes — The file
Example#
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#
def export_vector_svg(self, export_vector_svg_request: ExportVectorSvgRequest) -> bytesExport 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).
| Operation | ExportVectorSvg · POST /openapi/model/ExportVectorSvg |
|---|---|
| Scope | geometry:read |
Parameters#
| Name | Type | Description |
|---|---|---|
export_vector_svg_request | ExportVectorSvgRequestrequired | The request: its properties are those of the model, its JSON that of ExportVectorSvg's request body. |
Returns#
bytes — The drawing
Example#
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#
def get_checkin(self, get_checkin_request: GetCheckinRequest) -> CheckinStatusThe 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.
| Operation | GetCheckin · POST /openapi/model/GetCheckin |
|---|---|
| Scope | fs:read |
Parameters#
| Name | Type | Description |
|---|---|---|
get_checkin_request | GetCheckinRequestrequired | The request: its properties are those of the model, its JSON that of GetCheckin's request body. |
Returns#
CheckinStatus — The status
Example#
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#
def get_validation_report(self, get_validation_report_request: Optional[GetValidationReportRequest] = None) -> ValidationReportResultWhy 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.
| Operation | GetValidationReport · POST /openapi/model/GetValidationReport |
|---|---|
| Scope | query:run |
Parameters#
| Name | Type | Description |
|---|---|---|
get_validation_report_request | GetValidationReportRequestoptional | The request: its properties are those of the model, its JSON that of GetValidationReport's request body. |
Returns#
ValidationReportResult — The report
Example#
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#
def lookup_model_hashes(self, lookup_model_hashes_request: LookupModelHashesRequest) -> LookupModelHashes200ResponseWhich 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.
| Operation | LookupModelHashes · POST /openapi/model/LookupModelHashes |
|---|---|
| Scope | model:upload |
Parameters#
| Name | Type | Description |
|---|---|---|
lookup_model_hashes_request | LookupModelHashesRequestrequired | The 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#
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#
def render(self, render_request: RenderRequest) -> bytesA 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.
| Operation | Render · POST /openapi/model/Render |
|---|---|
| Scope | geometry:read |
Parameters#
| Name | Type | Description |
|---|---|---|
render_request | RenderRequestrequired | The request: its properties are those of the model, its JSON that of Render's request body. |
Returns#
bytes — The image
Example#
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#
def schema_conversion_report(self, schema_conversion_report_request: SchemaConversionReportRequest) -> SchemaConversionReportResponseThe 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.
| Operation | SchemaConversionReport · POST /openapi/model/SchemaConversionReport |
|---|---|
| Scope | model:read |
Parameters#
| Name | Type | Description |
|---|---|---|
schema_conversion_report_request | SchemaConversionReportRequestrequired | The 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#
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#
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) -> ModelVersionUpload 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.
| Operation | UploadModel · POST /openapi/model/UploadModel |
|---|---|
| Scope | model:upload |
Parameters#
| Name | Type | Description |
|---|---|---|
file | bytesoptional | The file. A single uploaded model |
node_uuid | UUIDoptional | The UUID of the Node to which to add the models |
filename | stroptional | Name of the file |
filesize | intoptional | Filesize in bytes |
content_type | stroptional | The 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_type | stroptional | The type of the model (an InputFileType name). When present and not UNKNOWN it wins over the filename extension |
format_settings | stroptional | A JSON-encoded PointCloudFormatSettings object (multipart form fields are strings) with per-upload point cloud format options |
hash | stroptional | Instead 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_reprocessing | booloptional | Process the file again, also when the server has processed the same file before |
tags | stroptional | Tags of the new Version, comma-separated VersionTag names |
validation_settings | stroptional | A JSON-encoded ValidationSettings object |
wait_ms | intoptional | Answer 202 with the checkin's status when the checkin takes longer than this |
force | stroptional | An UploadForce: NONE, NEW_VERSION or NEW_MODEL |
Returns#
ModelVersion — Upload was successful
Example#
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))