### Initializing BIMserver Client and Displaying Version (JavaScript) Source: https://github.com/opensourcebim/bimserver-javascript-api/blob/master/index.html A concise example showing the initialization of the BIMserver client and displaying the BIMserver version on a webpage element. This is often used for verifying the connection and version information. ```javascript import BimServerClient from './bimserverclient.js'; var api = new BimServerClient("../.."); api.init((client, version) => { document.getElementById("version").innerHTML = JSON.stringify(version.version, 0, 2); }); ``` -------------------------------- ### Install NPM Dependencies Source: https://github.com/opensourcebim/bimserver-javascript-api/blob/master/README.md Installs the project's build dependencies using npm (Node Package Manager). This command should be run after navigating into the project directory. ```bash npm install ``` -------------------------------- ### Start Transaction for Model Editing (JavaScript) Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Begins a transaction on a model, which is necessary for creating, modifying, or deleting objects. Changes are only applied upon committing the transaction. This example demonstrates creating a wall, setting its properties, and committing the changes. ```javascript const model = api.createModel(projectOid, (createdModel) => { console.log("Model initialized"); }); model.startTransaction((transactionId) => { console.log("Transaction started:", transactionId); const wall = model.create("IfcWall", {}, (createdWall) => { console.log("Wall created with OID:", createdWall.oid); createdWall.setName("North Wall"); createdWall.setGlobalId("3vB2YO$Fz0ng8Q2PwQq5zX"); model.commit("Added north wall", (revisionOid) => { console.log("Changes committed to revision:", revisionOid); }); }); }); ``` -------------------------------- ### Upload IFC File (Check-in) with Javascript Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Uploads an IFC file to a project, initiating a check-in process. It first calls `initiateCheckin` to get a `topicId`, then uses `checkin` to perform the actual upload. The process includes callbacks for progress updates (percentage), successful check-in (returning a `checkinId`), and error handling. ```javascript const project = { oid: 131073 }; const deserializerOid = 1048577; // IFC deserializer OID const file = document.getElementById("fileInput").files[0]; const comment = "Initial upload of building model"; api.initiateCheckin(project, deserializerOid, (topicId) => { console.log("Check-in initiated, topic ID:", topicId); api.checkin( topicId, project, comment, file, deserializerOid, (percentage) => { console.log("Upload progress:", percentage + "%"); }, (checkinId) => { console.log("Check-in successful:", checkinId); }, (error) => { console.error("Check-in failed:", error.message); } ); }, (error) => { console.error("Failed to initiate check-in:", error.message); } ); ``` -------------------------------- ### Query Model by GUIDs (JavaScript) Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Retrieves IFC objects from a model using their GlobalId (GUIDs). The GUID is the standard IFC unique identifier for building elements. The results are processed via a callback for each found object, with a final callback upon completion. ```javascript const guids = [ "2O2Fr$t4X7Zf8NOew3FLOH", "2O2Fr$t4X7Zf8NOew3FL0I", "2O2Fr$t4X7Zf8NOew3FL0J" ]; model.getByGuids(guids, (object) => { console.log("Found object:", object.getType()); console.log("OID:", object.oid); object.getGlobalId((guid) => { console.log("GUID:", guid); }); }).done(() => { console.log("All GUID lookups complete"); }); ``` -------------------------------- ### Get Serializer by Plugin Class Name with Javascript Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Retrieves a serializer configuration by providing its plugin class name. This method returns a Promise that resolves with the serializer object, which contains details like its name, OID, plugin class name, and enabled status. The retrieved serializer can then be used for operations like downloading models. ```javascript api.getSerializerByPluginClassName("org.bimserver.ifc.step.serializer.IfcStepSerializerPlugin") .then((serializer) => { console.log("Serializer:", serializer.name); console.log("OID:", serializer.oid); console.log("Plugin:", serializer.pluginDescriptor.pluginClassName); console.log("Enabled:", serializer.enabled); // Use serializer for download api.call("ServiceInterface", "download", { roids: [262145], serializerOid: serializer.oid, sync: false }, (topicId) => { console.log("Download initiated:", topicId); }); }); ``` -------------------------------- ### Clone Project Repository Source: https://github.com/opensourcebim/bimserver-javascript-api/blob/master/README.md Instructions for cloning the BIMserver-JavaScript-API project from its GitHub repository using Git. This is the first step in building the library locally. ```bash git clone https://github.com/opensourceBIM/BIMserver-JavaScript-API.git ``` -------------------------------- ### Dynamic Import of BIMserver API Components (JavaScript) Source: https://github.com/opensourcebim/bimserver-javascript-api/blob/master/index.html Illustrates dynamic import for loading BIMserver API components when their location is not known beforehand. This approach is useful for more flexible loading, though it might require a 'dev' version of the API in some browsers. It uses Promise.all to load multiple modules and then initializes the client. ```javascript var address = "http://addressofapi"; Promise.all([ address + "/bimserverclient.js", address + "/bimserverapipromise.js" ].map(x => import(x))) .then(([BimServerClient, BimServerApiPromise]) => { var api = new BimServerClient.BimServerClient("../.."); api.init((client, version) => { document.getElementById("version").innerHTML = JSON.stringify(version.version, 0, 2); }); }); ``` -------------------------------- ### Initialize BIMserver Client Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Creates a new BIMserver client instance, connects to the server, and retrieves server information along with schema definitions. This is the first step before any other API operations can be performed. Dependencies include the BimServerClient class. ```javascript import { BimServerClient } from './bimserverclient.js'; const api = new BimServerClient("https://example.com/bimserver"); api.init((client, serverInfo) => { console.log("Connected to BIMserver version:", serverInfo.version); console.log("Server info:", serverInfo); }).catch(error => { console.error("Failed to initialize:", error); }); ``` -------------------------------- ### Static Import of BIMserver Client (JavaScript) Source: https://github.com/opensourcebim/bimserver-javascript-api/blob/master/index.html Demonstrates how to statically import the BIMserver client library. This method relies on the module system to handle all dependencies. It initializes the client and logs the BIMserver version. ```javascript import BimServerClient from './bimserverclient.js'; // Create a new API, the path given should point to the base path of a BIMserver. This can also be a full URL like "http://bimserveraddress" var api = new BimServerClient("../.."); api.init((client, version) => { console.log(version.version); }); ``` -------------------------------- ### Run Build Script Source: https://github.com/opensourcebim/bimserver-javascript-api/blob/master/README.md Executes the build script defined in the project's `package.json` file. This compiles the JavaScript API, with the output typically found in the `build/` directory. ```bash npm run build ``` -------------------------------- ### Navigate to Project Directory Source: https://github.com/opensourcebim/bimserver-javascript-api/blob/master/README.md Command to change the current directory to the cloned BIMserver-JavaScript-API project folder. This is necessary to run subsequent build commands. ```bash cd BIMserver-JavaScript-API ``` -------------------------------- ### Initialize BIMserver Client Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Initializes the BIMserver client, connects to the specified server URL, and retrieves server information along with schema definitions. ```APIDOC ## Initialize BIMserver Client ### Description Creates a new BIMserver client instance and connects to the server, retrieving server information and loading schema definitions for IFC2x3tc1, IFC4, and geometry classes. ### Method Constructor ### Endpoint N/A (Client Initialization) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { BimServerClient } from './bimserverclient.js'; const api = new BimServerClient("https://example.com/bimserver"); api.init((client, serverInfo) => { console.log("Connected to BIMserver version:", serverInfo.version); console.log("Server info:", serverInfo); }).catch(error => { console.error("Failed to initialize:", error); }); ``` ### Response #### Success Response (200) - **client** (object) - The initialized BIMserver client instance. - **serverInfo** (object) - An object containing information about the BIMserver instance. #### Response Example ```json { "version": "1.7.0", "downloadUrl": "https://example.com/bimserver/download", "users": [], "guid": "some-guid", "name": "BIMserver" } ``` ``` -------------------------------- ### Include Library via Script Tag Source: https://github.com/opensourcebim/bimserver-javascript-api/blob/master/README.md This method involves downloading the minified library and including it in your HTML file using a script tag. The `?_v=%VERSION%` parameter is used for efficient caching. ```html ``` -------------------------------- ### User Authentication (Login) Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Authenticates a user with provided credentials, stores the authentication token, and establishes a WebSocket connection for real-time updates. ```APIDOC ## User Authentication (Login) ### Description Authenticates a user with username and password, stores the authentication token, and establishes a WebSocket connection for real-time updates. ### Method `login(username, password, successCallback, errorCallback, options)` ### Endpoint N/A (Authentication) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (Credentials passed as arguments) ### Request Example ```javascript api.login("user@example.com", "password123", (user) => { console.log("Logged in as:", user.name); console.log("User ID:", user.oid); console.log("User type:", user.userType); }, (error) => { console.error("Login failed:", error.message); }, { busy: true, done: true, error: true } // Optional options ); ``` ### Response #### Success Response - **user** (object) - Information about the logged-in user. - **oid** (number) - User's unique identifier. - **name** (string) - User's name. - **userType** (string) - Type of the user (e.g., 'ADMIN', 'USER'). #### Response Example ```json { "oid": 12345, "name": "John Doe", "userType": "USER" } ``` ``` -------------------------------- ### Import as ES6 Module Source: https://github.com/opensourcebim/bimserver-javascript-api/blob/master/README.md Demonstrates how to import the BIMserver client as an ES6 module, suitable for use with modern JavaScript environments, transpilers, or bundlers. This allows for cleaner code organization and dependency management. ```javascript import { BimServerClient } from './js/bimserverclient.js'; const api = new BimServerClient("../.."); api.init((client, version) => { console.log(version.version); }); ``` -------------------------------- ### Download Model Revision with Javascript Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Downloads a specific model revision in a given format. It first retrieves a JSON streaming serializer, then calls the 'download' method with the revision OID and serializer OID. Finally, it generates a download URL and initiates the download by setting `window.location.href`. ```javascript const revisionOid = 262145; api.getJsonStreamingSerializer((serializer) => { api.call("ServiceInterface", "download", { roids: [revisionOid], serializerOid: serializer.oid, sync: false }, (topicId) => { const downloadUrl = api.generateRevisionDownloadUrl({ topicId: topicId, zip: true }); console.log("Download URL:", downloadUrl); window.location.href = downloadUrl; }); }); ``` -------------------------------- ### User Authentication with Username/Password Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Authenticates a user by providing their username and password. Upon successful authentication, it stores the authentication token and establishes a WebSocket connection for real-time updates. The function accepts a callback for successful login and another for errors, along with an options object. ```javascript api.login("user@example.com", "password123", (user) => { console.log("Logged in as:", user.name); console.log("User ID:", user.oid); console.log("User type:", user.userType); }, (error) => { console.error("Login failed:", error.message); }, { busy: true, done: true, error: true } ); ``` -------------------------------- ### Call BIMserver Service Methods Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Invokes any BIMserver API method by specifying the interface, method name, and parameters. Supports configurable UI feedback. ```APIDOC ## Call BIMserver Service Methods ### Description Invokes any BIMserver API method using interface name, method name, and parameters. Supports callback-based error handling and UI indication control. ### Method `call(serviceInterface, method, parameters, successCallback, errorCallback, showBusy, showDone, showError)` ### Endpoint N/A (Service Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (Parameters passed as arguments) ### Request Example ```javascript api.call("ServiceInterface", "getAllProjects", { onlyTopLevel: false, onlyActive: true }, (projects) => { projects.forEach(project => { console.log("Project:", project.name, "ID:", project.oid); console.log("Last revised:", new Date(project.lastRevisionDate)); }); }, (error) => { console.error("Failed to fetch projects:", error.message); }, true, // showBusy false, // showDone true // showError ); ``` ### Response #### Success Response - The response structure depends on the called method. For `getAllProjects`, it's an array of project objects. - **name** (string) - Name of the project. - **oid** (number) - Project unique identifier. - **lastRevisionDate** (number) - Timestamp of the last revision. #### Response Example (for getAllProjects) ```json [ { "oid": 131073, "name": "Project Alpha", "lastRevisionDate": 1678886400000 } ] ``` ``` -------------------------------- ### Load BIM Model Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Loads a specific revision of a BIM model. Supports deep loading (all objects immediately) or lazy loading (on-demand). ```APIDOC ## Load BIM Model ### Description Loads a BIM model revision with optional deep loading that fetches all objects immediately, or lazy loading that fetches objects on demand. ### Method `getModel(projectOid, revisionOid, schema, deepLoad, callback, modelName)` ### Endpoint N/A (Model Loading) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (Parameters passed as arguments) ### Request Example ```javascript const projectOid = 131073; const revisionOid = 262145; const schema = "ifc2x3tc1"; const deepLoad = true; const model = api.getModel(projectOid, revisionOid, schema, deepLoad, (loadedModel) => { console.log("Model loaded:", loadedModel.name); console.log("Project OID:", loadedModel.poid); console.log("Revision OID:", loadedModel.roid); console.log("Objects loaded:", Object.keys(loadedModel.objects).length); }, "My Building Model" // Optional model name ); ``` ### Response #### Success Response - **loadedModel** (object) - The loaded BIM model object. - **name** (string) - The name of the model. - **poid** (number) - Project OID. - **roid** (number) - Revision OID. - **objects** (object) - A collection of model objects. #### Response Example ```json { "name": "My Building Model", "poid": 131073, "roid": 262145, "schema": "ifc2x3tc1", "objects": { "1": { "oid": 1, "name": "Wall", "type": "IfcWall", // ... other properties } // ... other objects } } ``` ``` -------------------------------- ### Load BIM Model Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Loads a specific BIM model revision from BIMserver. It supports both deep loading (fetching all objects immediately) and lazy loading (fetching objects on demand). The function requires project OID, revision OID, schema, and a deep load flag, and accepts callbacks for successful loading and a model name. ```javascript const projectOid = 131073; const revisionOid = 262145; const schema = "ifc2x3tc1"; const deepLoad = true; const model = api.getModel(projectOid, revisionOid, schema, deepLoad, (loadedModel) => { console.log("Model loaded:", loadedModel.name); console.log("Project OID:", loadedModel.poid); console.log("Revision OID:", loadedModel.roid); console.log("Objects loaded:", Object.keys(loadedModel.objects).length); }, "My Building Model" ); ``` -------------------------------- ### Multi-Call API Requests Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Executes multiple BIMserver API calls in a single request to minimize network overhead and enhance batch operation efficiency. ```APIDOC ## Multi-Call API Requests ### Description Executes multiple API calls in a single request, reducing network overhead and improving performance for batch operations. ### Method `multiCall(requests, successCallback, errorCallback)` ### Endpoint N/A (Batch Service Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (Requests passed as arguments) ### Request Example ```javascript const requests = [ ["ServiceInterface", "getAllProjects", { onlyActive: true }], ["AuthInterface", "getLoggedInUser", {}], ["PluginInterface", "getAllSerializers", { onlyEnabled: true }] ]; api.multiCall(requests, (responses) => { const projects = responses[0].result; const user = responses[1].result; const serializers = responses[2].result; console.log("Projects:", projects.length); console.log("User:", user.name); console.log("Serializers:", serializers.length); }, (errors) => { console.error("Multi-call failed:", errors); } ); ``` ### Response #### Success Response - **responses** (array) - An array where each element corresponds to a request and contains `result` and `error` fields. - **result** (any) - The result of the successful API call. - **error** (object | null) - An error object if the call failed, otherwise null. #### Response Example ```json [ { "result": [ { "oid": 131073, "name": "Project Alpha", "lastRevisionDate": 1678886400000 } ], "error": null }, { "result": { "oid": 12345, "name": "John Doe", "userType": "USER" }, "error": null }, { "result": [ { "name": "Ifc2x3TC1", "guid": "...", "enabled": true } ], "error": null } ] ``` ``` -------------------------------- ### Register WebSocket Event Handlers (JavaScript) Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Subscribes to real-time server notifications via WebSocket. This allows for immediate updates on events such as new revisions being added to a project, new projects being created, or progress notifications. Specific handlers can be registered for specific projects. ```javascript const projectOid = 131073; api.registerNewRevisionOnSpecificProjectHandler( projectOid, (notification) => { console.log("New revision on project:", notification.poid); console.log("Revision OID:", notification.roid); console.log("Comment:", notification.comment); console.log("User:", notification.userId); }, () => { console.log("Handler registered successfully"); } ); ``` -------------------------------- ### Download Binary Geometry Data via WebSocket with Javascript Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Streams binary geometry data efficiently over a WebSocket connection. It sets up a listener using `setBinaryDataListener` to process incoming `ArrayBuffer` data, extract message topic IDs, and log geometry vertex information. The listener is cleared once the data is processed. ```javascript const topicId = 12345; api.setBinaryDataListener(topicId, (arrayBuffer) => { const view = new DataView(arrayBuffer); const messageTopicId = view.getUint32(0, true) + 0x100000000 * view.getUint32(4, true); console.log("Received binary data for topic:", messageTopicId); console.log("Data size:", arrayBuffer.byteLength, "bytes"); // Process geometry data // Skip first 8 bytes (topic ID), then read vertex/index data const geometryData = new Float32Array(arrayBuffer, 8); console.log("Geometry vertices:", geometryData.length / 3); // Clean up listener when done api.clearBinaryDataListener(topicId); }); api.downloadViaWebsocket({ topicId: topicId, serializerOid: serializer.oid }); ``` -------------------------------- ### Set Token Authentication Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Authenticates the client using a pre-existing token, useful for session management or token-based authentication flows. ```APIDOC ## Set Token Authentication ### Description Authenticates using a pre-existing token instead of username/password, useful for maintaining sessions or token-based authentication flows. ### Method `setToken(token, successCallback, errorCallback)` ### Endpoint N/A (Authentication) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (Token passed as argument) ### Request Example ```javascript const token = "existing-auth-token-string"; api.setToken(token, () => { console.log("Authenticated with token"); console.log("User:", api.user.name); }, () => { console.error("Token authentication failed"); } ); ``` ### Response #### Success Response None directly returned, but the client is authenticated and `api.user` is populated. #### Response Example N/A ``` -------------------------------- ### Call BIMserver Service Methods Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Invokes any available BIMserver API method by specifying the interface name, method name, and parameters. It supports callback-based error handling and allows control over UI indicators for busy, done, and error states. This is a general-purpose method for interacting with BIMserver services. ```javascript api.call("ServiceInterface", "getAllProjects", { onlyTopLevel: false, onlyActive: true }, (projects) => { projects.forEach(project => { console.log("Project:", project.name, "ID:", project.oid); console.log("Last revised:", new Date(project.lastRevisionDate)); }); }, (error) => { console.error("Failed to fetch projects:", error.message); }, true, // showBusy false, // showDone true // showError ); ``` -------------------------------- ### Set Token Authentication Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Authenticates the client using a pre-existing token. This method is useful for maintaining sessions or when implementing token-based authentication flows. It takes the token string and callbacks for success and failure. ```javascript const token = "existing-auth-token-string"; api.setToken(token, () => { console.log("Authenticated with token"); console.log("User:", api.user.name); }, () => { console.error("Token authentication failed"); } ); ``` -------------------------------- ### Query Model by Object IDs (JavaScript) Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Fetches specific objects from a model using an array of their OIDs (Object IDs). This method supports efficient batching and caching of results. It processes each object through a callback and signals completion with a final `.done()` callback. ```javascript const objectIds = [131073, 131074, 131075, 131076]; model.get(objectIds, (object) => { console.log("Object type:", object.getType()); console.log("Object OID:", object.oid); console.log("Is loaded:", object.object._s === 1); if (object.isA("IfcProduct")) { object.getRepresentation((representation) => { if (representation) { console.log("Has geometry representation"); } }); } }).done(() => { console.log("All objects retrieved"); }); ``` -------------------------------- ### Multi-Call API Requests Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Executes multiple BIMserver API calls within a single request. This is beneficial for reducing network overhead and improving performance, especially for batch operations. The method takes an array of requests and provides callbacks for handling the array of responses or errors. ```javascript const requests = [ ["ServiceInterface", "getAllProjects", { onlyActive: true }], ["AuthInterface", "getLoggedInUser", {}], ["PluginInterface", "getAllSerializers", { onlyEnabled: true }] ]; api.multiCall(requests, (responses) => { const projects = responses[0].result; const user = responses[1].result; const serializers = responses[2].result; console.log("Projects:", projects.length); console.log("User:", user.name); console.log("Serializers:", serializers.length); }, (errors) => { console.error("Multi-call failed:", errors); } ); ``` -------------------------------- ### Advanced Model Query (JavaScript) Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Executes complex queries on BIM models using a structured query language. This query language supports filtering by type, specifying property conditions, and including/excluding related data. The query results are processed via a callback, with error handling and a final completion callback. ```javascript const query = { queries: [ { type: { name: "IfcWall", includeAllSubTypes: true }, include: { type: "IfcWall", field: "Representation", include: { type: "IfcProductRepresentation", field: "Representations" } } } ] }; model.query(query, (object) => { console.log("Object:", object.getType(), object.oid); object.getRepresentation((repr) => { if (repr) { console.log("Has representation"); } }); }, (error) => { console.error("Query failed:", error); } ).done(() => { console.log("Query complete"); }); ``` -------------------------------- ### Query Model Objects by Type (JavaScript) Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Retrieves all objects of a specific IFC type from a model. It can optionally include all subtypes in the inheritance hierarchy. This function is asynchronous and uses callbacks to process retrieved objects and a final callback upon completion. ```javascript model.getAllOfType("IfcWall", true, (wall) => { console.log("Wall:", wall.getType()); console.log("OID:", wall.oid); wall.getName((name) => { console.log("Name:", name); }); wall.getGlobalId((guid) => { console.log("GUID:", guid); }); }).done(() => { console.log("All walls retrieved"); }); ``` -------------------------------- ### Track Progress of Long Operations with Javascript Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Monitors the progress of long-running operations (e.g., downloads, uploads, geometry generation) by registering a progress handler. This handler receives real-time status updates, including progress percentage, title, and state (e.g., AS_ERROR, FINISHED). It also handles unregistering the handler upon successful completion or error. ```javascript const topicId = 12345; api.registerProgressHandler( topicId, (tId, progressState) => { console.log("Progress:", progressState.progress, "%"); console.log("Title:", progressState.title); console.log("State:", progressState.state); if (progressState.state === "AS_ERROR") { console.error("Operation failed:", progressState.errors); } if (progressState.state === "FINISHED") { console.log("Operation completed successfully"); api.unregisterProgressHandler(topicId, arguments.callee, () => { console.log("Progress handler unregistered"); }); } }, () => { console.log("Progress handler registered"); } ); ``` -------------------------------- ### Add Extended Data to Revision with Javascript Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Attaches additional data files (e.g., analysis results, reports) to a model revision. It first retrieves the schema definition for the extended data using `getExtendedDataSchemaById`, then uses `addExtendedData` to associate the file with the revision, title, and schema. ```javascript const revisionOid = 262145; const title = "Energy Analysis Results"; const file = document.getElementById("analysisFile").files[0]; const schemaOid = 2097153; api.call("ServiceInterface", "getExtendedDataSchemaById", { oid: schemaOid }, (schema) => { api.addExtendedData( revisionOid, title, schema, file, (result) => { console.log("Extended data added:", result); }, (error) => { console.error("Failed to add extended data:", error.message); } ); }); ``` -------------------------------- ### Logout User with JavaScript Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Terminates the current user session by invalidating the authentication token and closing WebSocket connections. This function requires an API object and redirects the user to the login page upon successful logout. ```javascript api.logout(() => { console.log("User logged out successfully"); api.token = null; api.user = null; window.location.href = "/login"; }); ``` -------------------------------- ### Check IFC Object Type Inheritance with JavaScript Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Tests if an IFC object is of a specific type or inherits from it in the IFC schema hierarchy. This function requires a model object and checks against various IFC types like IfcProduct, IfcElement, IfcWall, and IfcSlab. ```javascript model.get(131073, (object) => { console.log("Object type:", object.getType()); if (object.isA("IfcProduct")) { console.log("This is an IFC Product"); } if (object.isA("IfcElement")) { console.log("This is an IFC Element"); } if (object.isA("IfcWall")) { console.log("This is specifically a wall"); } else if (object.isA("IfcSlab")) { console.log("This is specifically a slab"); } }); ``` -------------------------------- ### Modify Model Object Properties (JavaScript) Source: https://context7.com/opensourcebim/bimserver-javascript-api/llms.txt Updates properties of existing IFC objects within an active transaction. This method supports modifying various data types, including strings, numbers, booleans, and references to other objects. Changes are committed to a new revision. ```javascript model.startTransaction((tid) => { model.get(131073, (wall) => { wall.setName("Updated Wall Name"); wall.setDescription("This is a modified description"); wall.getObjectType((objType) => { console.log("Current type:", objType); }); wall.setObjectType("LoadBearing"); model.commit("Updated wall properties", (roid) => { console.log("Committed revision:", roid); }); }); }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.