Commands
Use the following viewer utility function commands to enable users to access or set data structures stored in the viewer.
getSelectedEntities()#
Gets an array of ids for the selected elements in the viewer.
Returns
Array<String> - Returns an array of the selected elements' ids
Example#
//To use commands, first, import lodash, React and the useRef hook.import React, { useRef } from 'react';import _ from 'lodash'; //Assign the value of the userRef hook to a variable called viewerRef const viewerRef = useRef();
//To access the commands, create a commands variable with the following lodash calllet commands = _.get(viewerRef, "current.iafviewerRef.current.commands");
//Now you can access the commands with dot notationif (commands && commands.getSelectedEntities) { let pkgIds = await commands.getSelectedEntities();}getSettings()#
Gets the viewer's current settings in JSON format.
Returns
<JSON> - Returns a JSON object with the properties and values of the viewer's current settings.
Example#
//To use commands, first, import lodash, React and the useRef hook.import React, { useRef } from 'react';import _ from 'lodash'; //Assign the value of the userRef hook to a variable called viewerRef const viewerRef = useRef();
//To access the commands, create a commands variable with the following lodash calllet commands = _.get(viewerRef, "current.iafviewerRef.current.commands");
//Now you can access the commands with dot notationif (commands && commands.getSettings) { let settings = await commands.getSettings();}getIsolatedElements()#
Gets an array of the isolated elements' ids.
Returns
Array<String> - Returns an array of the isolated elements' ids.
Example#
//To use commands, first, import lodash, React and the useRef hook.import React, { useRef } from 'react';import _ from 'lodash'; //Assign the value of the userRef hook to a variable called viewerRef const viewerRef = useRef();
//To access the commands, create a commands variable with the following lodash calllet commands = _.get(viewerRef, "current.iafviewerRef.current.commands");
//Now you can access the commands with dot notationif (commands && commands.getIsolatedElements) { let isoElems = await commands.getIsolatedElements();}getHiddenElements()#
Gets an array of the hidden elements' ids.
Returns
Array<String> - Returns an array of the hidden elements' ids.
Example#
//To use commands, first, import lodash, React and the useRef hook.import React, { useRef } from 'react';import _ from 'lodash'; //Assign the value of the userRef hook to a variable called viewerRef const viewerRef = useRef();
//To access the commands, create a commands variable with the following lodash calllet commands = _.get(viewerRef, "current.iafviewerRef.current.commands");
//Now you can access the commands with dot notationif (commands && commands.getHiddenElements) { let isoElems = await commands.getHiddenElements();}getCuttingPlanes()#
Gets the current cutting plane values.
Returns
<JSON> - Returns a JSON object with the cutting plane max and min x, y, and z coordinates.
Example#
//To use commands, first, import lodash, React and the useRef hook.import React, { useRef } from 'react';import _ from 'lodash'; //Assign the value of the userRef hook to a variable called viewerRef const viewerRef = useRef();
//To access the commands, create a commands variable with the following lodash calllet commands = _.get(viewerRef, "current.iafviewerRef.current.commands");
//Now you can access the commands with dot notationif (commands && commands.getCuttingPlanes) { let cuttingPlanes = await commands.getCuttingPlanes();}Example cutting plane JSON object that returns:
{ "max": { "x": 60665.3359375, "y": 48933.6171875, "z": 14610 }, "min": { "x": -72522.125, "y": -72522.125, "z": -72522.125 }}setCuttingPlanes()#
Sets the cutting planes' values.
Parameters
| Parameter | Type | Description |
|---|---|---|
| obj | JSON | Pass an object that contains the the max and the min cutting plane objects. |
| obj.max | JSON | Pass an object that contains the maximum "x", "y", and "z" cutting plane coordinates as parameters. |
| obj.min | JSON | Pass an object that contains the minimum "x", "y", and "z" cutting plane coordinates as parameters. |
Returns
none
Example#
//To use commands, first, import lodash, React and the useRef hook.import React, { useRef } from 'react';import _ from 'lodash';
//Create an object that contains the cutting plane values for the max x, y, and z values, and the min x, y, and z values.let obj = { "max": { "x": 60665.3359375, "y": 48933.6171875, "z": 14610 }, "min": { "x": -72522.125, "y": -72522.125, "z": -72522.125 }}; //Assign the value of the userRef hook to a variable called viewerRef const viewerRef = useRef();
//To access the commands, create a commands variable with the following lodash calllet commands = _.get(viewerRef, "current.iafviewerRef.current.commands");
//Now you can access the commands with dot notationif (commands && commands.setCuttingPlanes) { let cuttingPlanes = await commands.setCuttingPlanes(values);}getCamera()#
Gets a JSON object with the camera properties.
Returns
<JSON> - Returns a JSON object with the camera position and properties.
Example#
//To use commands, first, import lodash, React and the useRef hook.import React, { useRef } from 'react';import _ from 'lodash'; //Assign the value of the userRef hook to a variable called viewerRef const viewerRef = useRef();
//To access the commands, create a commands variable with the following lodash calllet commands = _.get(viewerRef, "current.iafviewerRef.current.commands");
//Now you can access the commands with dot notationif (commands && commands.getSettings) { let cameraProps = await commands.getCamera();}
Example camera position and properties JSON object that returns:
{ "position": { "x": -71503.14101725465, "y": -77040.72626505737, "z": 75165.62786425062 }, "target": { "x": 770.4948303222656, "y": -4767.090417480468, "z": 2891.9920166737224 }, "up": { "x": 0.4082482904638631, "y": 0.4082482904638631, "z": 0.8164965809277261 }, "width": 181899.5258131281, "height": 181899.5258131281, "projection": 1, "nearLimit": 0.001, "className": "Communicator.Camera"}setCamera()#
Sets the camera position and properties when you pass a JSON object.
Parameters
| Parameter | Type | Description |
|---|---|---|
| jsoncamera | JSON | Pass a JSON object with the camera position, position, target, up, width, height, projection, near limit and class name. |
| jsoncamera.position | JSON | Pass a JSON object with the camera "x", "y", and "z" coordinates as parameters. |
| jsoncamera.target | JSON | Pass a JSON object with the target "x", "y", and "z" coordinates as parameters. |
| jsoncamera.up | JSON | Pass a JSON object with the up "x", "y", and "z" coordinates as parameters. |
| jsoncamera.width | Number | Set the camera width. |
| jsoncamera.height | Number | Set the camera height. |
| jsoncamera.projection | Number | For orthographic, set to 1. For perspective, set to 2. |
| jsoncamera.nearLimit | JSON | Set the camera's near limit. |
| jsoncamera.className | JSON | Set the class name to Communicator.Camera |
Returns
none
Example#
//To use commands, first, import lodash, React and the useRef hook.import React, { useRef } from 'react';import _ from 'lodash';
//Create an object that contains the cutting plane values for the max x, y, and z values, and the min x, y, and z values.let jsoncamera = { "position": { "x": -71503.14101725465, "y": -77040.72626505737, "z": 75165.62786425062 }, "target": { "x": 770.4948303222656, "y": -4767.090417480468, "z": 2891.9920166737224 }, "up": { "x": 0.4082482904638631, "y": 0.4082482904638631, "z": 0.8164965809277261 }, "width": 181899.5258131281, "height": 181899.5258131281, "projection": 1, "nearLimit": 0.001, "className": "Communicator.Camera"}; //Assign the value of the userRef hook to a variable called viewerRef const viewerRef = useRef();
//To access the commands, create a commands variable with the following lodash calllet commands = _.get(viewerRef, "current.iafviewerRef.current.commands");
//Now you can access the commands with dot notationif (commands && commands.setCamera) { let cameraPos = await commands.setCamera(jsoncamera);}getView()#
Gets the properties of camera, cutting planes, draw mode, and selection.
Returns
<JSON> - Returns a JSON object with the camera, cutting planes, draw mode, and selection id properties.
Example#
//To use commands, first, import lodash, React and the useRef hook.import React, { useRef } from 'react';import _ from 'lodash'; //Assign the value of the userRef hook to a variable called viewerRef const viewerRef = useRef();
//To access the commands, create a commands variable with the following lodash calllet commands = _.get(viewerRef, "current.iafviewerRef.current.commands");
//Now you can access the commands with dot notationif (commands && commands.getView) { let view = await commands.getView();}
Example JSON object with camera, cutting planes, draw mode, and selection properties that returns:
{ camera:{ "position": { "x": -71503.14101725465, "y": -77040.72626505737, "z": 75165.62786425062 }, "target": { "x": 770.4948303222656, "y": -4767.090417480468, "z": 2891.9920166737224 }, "up": { "x": 0.4082482904638631, "y": 0.4082482904638631, "z": 0.8164965809277261 }, "width": 181899.5258131281, "height": 181899.5258131281, "projection": 1, "nearLimit": 0.001, "className": "Communicator.Camera" }, "cuttingPlanes": { "max": { "x": 60665.3359375, "y": 48933.6171875, "z": 14610 }, "min": { "x": -72522.125, "y": -72522.125, "z": -72522.125 } }, "drawMode": 1, "selection":[9192]}setView()#
Sets the camera position, cutting planes, draw mode, and selection id properties with a JSON object you pass.
Parameters
| Parameter | Type | Description |
|---|---|---|
| obj | JSON | A JSON object with the camera position, cutting planes, draw mode, and selected element ids. |
| obj.camera | JSON | Pass a JSON object with the camera position, cutting planes, draw mode, and selected element ids. |
| obj.camera.position | JSON | Pass a JSON object with the camera "x", "y", and "z" coordinates as parameters. |
| obj.camera.target | JSON | Pass a JSON object with the target "x", "y", and "z" coordinates as parameters. |
| obj.camera.up | JSON | Pass a JSON object with the up "x", "y", and "z" coordinates as parameters. |
| obj.camera.width | Number | The camera width. |
| obj.camera.height | Number | The camera height. |
| obj.camera.projection | Number | For orthographic, set to 1. For perspective, set to 2. |
| obj.camera.nearLimit | Number | Set the camera near limit. |
| obj.camera.className | JSON | Set the camera class name. |
| obj.cuttingPlanes | JSON | A JSON object with the cutting planes max and min coordinates. |
| obj.cuttingPlanes.max | JSON | A JSON object with the cutting plane maximum "x", "y", and "z" coordinates as parameters. |
| obj.cuttingPlanes.min | JSON | A JSON object with the cutting plane minimum "x", "y", and "z" coordinates as parameters. |
| obj.drawMode | Number | 0: Wireframe, 1: Shaded, 2: WireFrameOnShaded, 3: HiddenLine, 4: Xray. |
| obj.selection | Array of Number | An array that contains the currently selected elements' ids. |
Returns
none
Example#
//To use commands, first, import lodash, React and the useRef hook.import React, { useRef } from 'react';import _ from 'lodash';
//Create an object with your view properties.let obj = { camera:{ "position": { "x": -71503.14101725465, "y": -77040.72626505737, "z": 75165.62786425062 }, "target": { "x": 770.4948303222656, "y": -4767.090417480468, "z": 2891.9920166737224 }, "up": { "x": 0.4082482904638631, "y": 0.4082482904638631, "z": 0.8164965809277261 }, "width": 181899.5258131281, "height": 181899.5258131281, "projection": 1, "nearLimit": 0.001, "className": "Communicator.Camera" }, "cuttingPlanes": { "max": { "x": 60665.3359375, "y": 48933.6171875, "z": 14610 }, "min": { "x": -72522.125, "y": -72522.125, "z": -72522.125 } }, "drawMode": 1, "selection":[9192]}; //Assign the value of the userRef hook to a variable called viewerRef const viewerRef = useRef();
//To access the commands, create a commands variable with the following lodash calllet commands = _.get(viewerRef, "current.iafviewerRef.current.commands");
//Now you can access the commands with dot notationif (commands && commands.setView) { let view = await commands.setView(obj);}