Skip to main content
Version: v4.6

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

ParameterTypeDescription
objJSONPass an object that contains the the max and the min cutting plane objects.
obj.maxJSONPass an object that contains the maximum "x", "y", and "z" cutting plane coordinates as parameters.
obj.minJSONPass 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

ParameterTypeDescription
jsoncameraJSONPass a JSON object with the camera position, position, target, up, width, height, projection, near limit and class name.
jsoncamera.positionJSONPass a JSON object with the camera "x", "y", and "z" coordinates as parameters.
jsoncamera.targetJSONPass a JSON object with the target "x", "y", and "z" coordinates as parameters.
jsoncamera.upJSONPass a JSON object with the up "x", "y", and "z" coordinates as parameters.
jsoncamera.widthNumberSet the camera width.
jsoncamera.heightNumberSet the camera height.
jsoncamera.projectionNumberFor orthographic, set to 1. For perspective, set to 2.
jsoncamera.nearLimitJSONSet the camera's near limit.
jsoncamera.classNameJSONSet 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

ParameterTypeDescription
objJSONA JSON object with the camera position, cutting planes, draw mode, and selected element ids.
obj.cameraJSONPass a JSON object with the camera position, cutting planes, draw mode, and selected element ids.
obj.camera.positionJSONPass a JSON object with the camera "x", "y", and "z" coordinates as parameters.
obj.camera.targetJSONPass a JSON object with the target "x", "y", and "z" coordinates as parameters.
obj.camera.upJSONPass a JSON object with the up "x", "y", and "z" coordinates as parameters.
obj.camera.widthNumberThe camera width.
obj.camera.heightNumberThe camera height.
obj.camera.projectionNumberFor orthographic, set to 1. For perspective, set to 2.
obj.camera.nearLimitNumberSet the camera near limit.
obj.camera.classNameJSONSet the camera class name.
obj.cuttingPlanesJSONA JSON object with the cutting planes max and min coordinates.
obj.cuttingPlanes.maxJSONA JSON object with the cutting plane maximum "x", "y", and "z" coordinates as parameters.
obj.cuttingPlanes.minJSONA JSON object with the cutting plane minimum "x", "y", and "z" coordinates as parameters.
obj.drawModeNumber0: Wireframe, 1: Shaded, 2: WireFrameOnShaded, 3: HiddenLine, 4: Xray.
obj.selectionArray of NumberAn 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);}