Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ XR Studio

Runtime::Scene

  • Last UpdatedSep 05, 2024
  • 3 minute read

The Runtime::Scene class provides useful functionalities for accessing and modifying nodes in the scene.

Code example

This is a code example for Runtime::Scene.

List<string> a=Runtime::Scene.EnumerateFields("Player0_Avatar,all");

List<string> a=Runtime::Scene.EnumerateGroups("all");

List<string> a=Runtime::Scene.EnumerateNodes("items");

Runtime::Scene.ExecuteSFunction("viewport_DEFAULT_VIEWPORT.getSceneLayerCamera","hello");

Runtime::Scene.ExecuteSFunction("viewport_DEFAULT_VIEWPORT.getSceneLayerCamera");

bool b= Runtime::Scene.ExistsDefine("system.platform"); //b= True if system.platform node exists

bool b= Runtime::Scene.ExistsNode("Player0_Avatar"); //b= True if Player0_Avatar node exists

string s= Runtime::Scene.GetDefine("system.platforms"); //s=win64;

double v=Runtime::Scene.GetFieldValue("Player0_Avatar.behindFov"); //v=85;

var avatar= Runtime::Scene.GetNode("Player0_Avatar"); //s=Player0_Avatar

Runtime::Environment.Print("@def:system.debug@: "+Runtime::Scene.Resolve("@def:system.debug@")); //@def:system.debug@: true

Runtime::Scene.SetFieldValue("testVar.value", “hello world”); //here testVar is a Var of type sstring in the Graphics Context

Runtime::Scene.SetFieldValue("testVar.value", value); //here testVar is a Var of type sdouble in the Graphics Context and string value = "9.3";

In regards to Runtime::Scene.GetNode, when a node is retrieved, it is possible to access its fields by using the syntax: nodeName.fieldName as shown in the following example:

var avatar = Runtime::Scene.GetNode("Player0_Avatar");

avatar.behindFov = 50;

double v = avatar.behindFov; //v=85; avatar.behindFov=85

v = 34; //v=34; avatar.behindFov=85

avatar.behindFov = v; //v=34; avatar.behindFov=34

Node fields can be used for variable assignment, as shown in the previous example.

However, they cannot be used inside of methods or statement calls. The following example code will raise an error.

Incorrect example—Node fields cannot be used inside methods

var clipNode= Runtime::Scene.GetNode("clipping_node");

if(clipNode.enabled==true) //Raises an error

{

Runtime::Environment.Print("clip enabled");

}

Correct example—Use this approach instead

var clipNode= Runtime::Scene.GetNode("clipping_node");

bool clipNodeEnabled= clipNode.enabled;

if(clipNodeEnabled ==true) //Doesn’t’ raise an error

{

Runtime::Environment.Print("clip enabled");

}

Methods

The following table shows the currently implemented methods.  

Method 

Return type 

Parameters 

Description 

EnumerateFields 

List<string> 

string value 

Gets a List<string> of field names. The value string is composed by two comma-separated parameters: the first parameter is the node name and the second parameter is used to restrict the fields. For the second parameter, the possible options are: 

  • all - returns all the fields of the node. 

  • action - returns all the action fields of the node, both standard and user defined. 

  • type:fieldType - returns all and only the fields of the specified fieldType. 

    Parameter syntax is the same as the corresponding XML scripting. See Special assignment prefixes.

EnumerateGroups 

List<string> 

string value 

Gets a List<string> of group names. value string can be:  

  • all - returns all the different group names or the name of the item, if it has no group.

  • groupContains:text - restricts the returned list to those whose group name (or name if no group is set) contains a certain text.

  • groupContainsActive:text - restricts the returned list to those whose group name (or name if no group is set) contains a certain text, but restricts the returned list to active items or items with showItemWhenInactive set to true. 

    Parameter syntax is the same as the corresponding XML scripting. See Special assignment prefixes.

EnumerateNodes 

List<string> 

string value 

Gets a List<string> of node names. The value string can be: 

  • all - returns all the nodes. 

  • items - returns all the nodes of item type. 

  • type:nodeType - returns all nodes of the specified nodeType.

  • group:groupName - returns all the items included in the groupName, if any. 

  • itemContains:text - returns all items whose name contains the given text. 

  • groupContains:text - returns all items whose group name contains the given text. 

    Parameter syntax is the same as the corresponding XML scripting. See Special assignment prefixes.

ExecuteSFunction 

string 

string sFunctionName, 

string par 

Executes a field sFunction (sFunctionName) passing a parameter par (optional) at a specific moment. 

ExistsDefine 

bool 

string defineName 

Returns true if a define defineName exists. 

ExistsNode 

bool 

string nodeName 

Returns true if a node nodeName exists. 

GetDefine 

string 

string defineName 

Returns the define value corresponding to defineName, if one exists; otherwise, throws an exception. 

GetFieldValue 

type 

string fieldName 

Returns the value of the field node corresponding to fieldName, if one exists; otherwise, throws an exception. The fieldName string uses the syntax nodeName.fieldName. Return type depends on the field type. 

GetNode 

var 

string nodeName 

Returns the node corresponding to nodeName, if one exists; otherwise, throws an exception. 

Resolve 

string 

string value 

Resolves the string value using the engine internal resolve system used by XML script. 

SetFieldValue 

 

string fieldName, type value 

Sets the value of the field of a node corresponding to fieldname to value. If fieldName does not exist, it throws an exception. The fieldName string uses the syntax nodeName.fieldName. The type of value depends on the field type. It can be the same type or one that can be cast to that type. 

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in