44
55This package provides a TypeScript client and types for interacting with the [ Scenes API] ( https://developer.bentley.com/apis/scenes/ ) .
66
7-
87## Installation
98
109``` bash
@@ -20,21 +19,25 @@ pnpm add @bentley/scenes-client
2019``` ts
2120import { SceneClient } from " @bentley/scenes-client" ;
2221
23- const client = new SceneClient ({
24- getAccessToken : async () => " <itwin_platform_auth_token>" ,
25- baseUrl: " <HOST_URL>" , // Optional, defaults to "https://api.bentley.com/scenes"
26- } );
22+ const client = new SceneClient (
23+ async () => " <itwin_platform_auth_token>" ,
24+ " <HOST_URL>" , // Optional, defaults to "https://api.bentley.com/scenes"
25+ );
2726```
27+
2828---
29+
2930### Working with Scenes
3031
3132#### Get a Scene
3233
3334``` ts
35+ import { OrderByProperties } from " @bentley/scenes-client" ;
36+
3437const sceneResponse = await client .getScene ({
3538 iTwinId: " <itwin_id>" ,
3639 sceneId: " <scene_id>" ,
37- orderBy: " displayName " , // Optional property to order scene data by
40+ orderBy: OrderByProperties . NAME , // Optional property to order scene data by
3841});
3942
4043console .log (sceneResponse .scene );
@@ -55,22 +58,26 @@ console.log(sceneResponse.scene);
5558#### Get List of Scenes for an iTwin
5659
5760``` ts
61+ import { SceneMinimal } from " @bentley/scenes-client" ;
62+
5863// Get a single page of scenes (for UI pagination)
5964const listResponse = await client .getScenes ({
6065 iTwinId: " <itwin_id>" ,
6166 top: 10 , // Optional, defaults to 100
62- skip: 5 // Optional, defaults to 0
67+ skip: 5 , // Optional, defaults to 0
6368});
6469
6570console .log (` Found ${listResponse .scenes .length } scenes on this page. ` );
66- listResponse .scenes .forEach (scene => {
71+ listResponse .scenes .forEach (( scene : SceneMinimal ) => {
6772 console .log (` ${scene .displayName } (${scene .id }) ` );
6873});
6974```
7075
7176#### Get All Scenes with Iterator
7277
7378``` ts
79+ import { SceneMinimal } from " @bentley/scenes-client" ;
80+
7481// Get all scenes using async iterator
7582const allScenesIterator = await client .getAllScenes ({
7683 iTwinId: " <itwin_id>" ,
@@ -79,7 +86,7 @@ const allScenesIterator = await client.getAllScenes({
7986let totalScenes = 0 ;
8087for await (const page of allScenesIterator ) {
8188 console .log (` Processing ${page .scenes .length } scenes... ` );
82- page .scenes .forEach (scene => {
89+ page .scenes .forEach (( scene : SceneMinimal ) => {
8390 console .log (` ${scene .displayName } ` );
8491 totalScenes ++ ;
8592 });
@@ -96,9 +103,9 @@ const createResponse = await client.postScene({
96103 scene: {
97104 displayName: " Construction Site Overview" ,
98105 sceneData: {
99- objects: []
100- }
101- }
106+ objects: [],
107+ },
108+ },
102109});
103110
104111console .log (` Created scene: ${createResponse .scene ! .displayName } ` );
@@ -111,8 +118,8 @@ const updateResponse = await client.patchScene({
111118 iTwinId: " <itwin_id>" ,
112119 sceneId: " <scene_id>" ,
113120 scene: {
114- displayName: " Updated Scene Name"
115- }
121+ displayName: " Updated Scene Name" ,
122+ },
116123});
117124
118125console .log (` Updated scene: ${updateResponse .scene ! .displayName } ` );
@@ -123,13 +130,12 @@ console.log(`Updated scene: ${updateResponse.scene!.displayName}`);
123130``` ts
124131await client .deleteScene ({
125132 iTwinId: " <itwin_id>" ,
126- sceneId: " <scene_id>"
133+ sceneId: " <scene_id>" ,
127134});
128135
129136console .log (" Scene deleted successfully" );
130137```
131138
132-
133139### Working with Scene Objects
134140
135141#### Get a Scene Object
@@ -138,7 +144,7 @@ console.log("Scene deleted successfully");
138144const objectResponse = await client .getObject ({
139145 iTwinId: " <itwin_id>" ,
140146 sceneId: " <scene_id>" ,
141- objectId: " <object_id>"
147+ objectId: " <object_id>" ,
142148});
143149
144150console .log (objectResponse .object );
@@ -160,34 +166,38 @@ console.log(objectResponse.object);
160166#### Get List of Objects in a Scene
161167
162168``` ts
169+ import { OrderByProperties , SceneObject } from " @bentley/scenes-client" ;
170+
163171// Get a single page of objects (for UI pagination)
164172const listResponse = await client .getObjects ({
165173 iTwinId: " <itwin_id>" ,
166174 sceneId: " <scene_id>" ,
167- orderBy: " displayName " , // Optional property to order results by
175+ orderBy: OrderByProperties . NAME , // Optional property to order results by
168176 top: 10 , // Optional, defaults to 100
169- skip: 5 // Optional, defaults to 0
177+ skip: 5 , // Optional, defaults to 0
170178});
171179
172180console .log (` Found ${listResponse .objects .length } objects on this page. ` );
173- listResponse .objects .forEach (object => {
181+ listResponse .objects .forEach (( object : SceneObject ) => {
174182 console .log (` ${object .displayName } (${object .id }) ` );
175183});
176184```
177185
178186#### Get All Objects with Iterator
179187
180188``` ts
189+ import { SceneObject } from " @bentley/scenes-client" ;
190+
181191// Get all objects in a scene using async iterator
182192const allObjectsIterator = await client .getAllObjects ({
183193 iTwinId: " <itwin_id>" ,
184- sceneId: " <scene_id>"
194+ sceneId: " <scene_id>" ,
185195});
186196
187197let totalObjects = 0 ;
188198for await (const page of allObjectsIterator ) {
189199 console .log (` Processing ${page .objects .length } objects... ` );
190- page .objects .forEach (object => {
200+ page .objects .forEach (( object : SceneObject ) => {
191201 console .log (` ${object .id } ` );
192202 totalObjects ++ ;
193203 });
@@ -199,8 +209,10 @@ console.log(`Processed ${totalObjects} total objects`);
199209#### Create Scene Objects
200210
201211``` ts
212+ import { SceneObject , SceneObjectCreate } from " @bentley/scenes-client" ;
213+
202214// Create objects in bulk
203- const objectsPayload = [
215+ const objectsPayload: SceneObjectCreate [] = [
204216 // Add a Layer
205217 {
206218 id: " <layer_id>" ,
@@ -209,8 +221,8 @@ const objectsPayload = [
209221 displayName: " Buildings" ,
210222 data: {
211223 visible: true ,
212- displayName: " Buildings"
213- }
224+ displayName: " Buildings" ,
225+ },
214226 },
215227 // Add an iModel resource
216228 {
@@ -223,8 +235,8 @@ const objectsPayload = [
223235 class: " iModels" ,
224236 repositoryId: " iModels" ,
225237 id: " <imodel_id>" ,
226- visible: true
227- }
238+ visible: true ,
239+ },
228240 },
229241 // Add a 3D view
230242 {
@@ -238,51 +250,52 @@ const objectsPayload = [
238250 aspectRatio: 1.33 ,
239251 near: 1 ,
240252 far: 1000 ,
241- ecefTransform: [1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 ]
242- }
243- }
253+ ecefTransform: [1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 ],
254+ },
255+ },
244256];
245257
246258// Create objects in bulk
247259const createResponse = await client .postObjects ({
248260 iTwinId: " <itwin_id>" ,
249261 sceneId: " <scene_id>" ,
250- objects: objectsPayload
262+ objects: objectsPayload ,
251263});
252264
253265console .log (` Created ${createResponse .objects .length } objects: ` );
254- createResponse .objects .forEach (obj => {
266+ createResponse .objects .forEach (( obj : SceneObject ) => {
255267 console .log (` Created ${obj .kind } object: ${obj .displayName } (${obj .id }) ` );
256268});
257-
258269```
259270
260271#### Update Scene Objects
261272
262273``` ts
274+ import { SceneObjectUpdate , SceneObjectUpdateById } from " @bentley/scenes-client" ;
275+
263276// Update a single object by id
264- const updatePayload = {
265- displayName: " Updated Object Name"
277+ const updatePayload: SceneObjectUpdate = {
278+ displayName: " Updated Object Name" ,
266279};
267280const updateResponse = await client .patchObject ({
268281 iTwinId: " <itwin_id>" ,
269282 sceneId: " <scene_id>" ,
270283 objectId: " <object_id>" ,
271- object: updatePayload
284+ object: updatePayload ,
272285});
273286
274287console .log (` Updated object: ${updateResponse .object .displayName } ` );
275288
276289// Update multiple objects in bulk (ex. reorder objects)
277- const bulkUpdatePayload = [
290+ const bulkUpdatePayload: SceneObjectUpdateById [] = [
278291 { id: " <object_id_1>" , order: 1 },
279292 { id: " <object_id_2>" , order: 2 },
280- { id: " <object_id_3>" , order: 3 }
293+ { id: " <object_id_3>" , order: 3 },
281294];
282295const bulkUpdateResponse = await client .patchObjects ({
283296 iTwinId: " <itwin_id>" ,
284297 sceneId: " <scene_id>" ,
285- objects: bulkUpdatePayload
298+ objects: bulkUpdatePayload ,
286299});
287300
288301console .log (` Updated ${bulkUpdateResponse .objects .length } objects ` );
@@ -295,18 +308,14 @@ console.log(`Updated ${bulkUpdateResponse.objects.length} objects`);
295308await client .deleteObject ({
296309 iTwinId: " <itwin_id>" ,
297310 sceneId: " <scene_id>" ,
298- objectId: " <object_id>"
311+ objectId: " <object_id>" ,
299312});
300313
301314// Delete objects in bulk
302315await client .deleteObjects ({
303316 iTwinId: " <itwin_id>" ,
304317 sceneId: " <scene_id>" ,
305- objectIds: [
306- " <object_id_1>" ,
307- " <object_id_2>" ,
308- " <object_id_3>"
309- ]
318+ objectIds: [" <object_id_1>" , " <object_id_2>" , " <object_id_3>" ],
310319});
311320```
312321
@@ -318,7 +327,7 @@ import { SceneApiError } from "@bentley/scenes-client";
318327try {
319328 const scene = await client .getScene ({
320329 iTwinId: " <itwin_id>" ,
321- sceneId: " <invalid_scene_id>"
330+ sceneId: " <invalid_scene_id>" ,
322331 });
323332} catch (error ) {
324333 if (error instanceof SceneApiError ) {
0 commit comments