Next (Objects) Previous (Scripting(Old))


In, an object is represented as a node, such as scene, mesh, material and so on. To operate an object using ctx scripting, we need to grab the object from the scene graph first using Selector and then apply the related operations.

Supported Selectors

To perform a selection, we need to use:

var myNodes = ctx(selector);

Here myNodes is an array of nodes that meet the selection criteria, wrapped in a ctx JavaScript object. To select a specific node, we must use the at function. For example, to get the 10th element of the array myNodes we employ:

var myNode =

Selection can be done in several ways. Below we review each of them:


This gets all objects that have been selected by the user in the viewport. The :selection rule allows a script to select the same nodes in the ctx as those in the viewport.

This can be used for instance to write a custom exporter that only exports those objects that were selected manually by the user on the viewport.


Selects all viewport selected objects.


This is used to select all objects of a particular type, in other words, all objects that belong to a given primitive. This selection is case insensitive. Valid types are the following:

  • %Scene - This is a common selection, and will retrieve the root node of the scene graph.

  • %Objects - The virtual node containing all objects.

  • %MaterialLibrary - The virtual node containing all materials.

  • %Materials - Select all materials.

  • %Renderers - The virtual node containing all renderers.

  • %Passes - The virtual node containing all passes.

  • %PolyMesh - Selects all polymesh (geometry) primitives.

  • %Annotation - Selects all annotation nodes.

  • %Light - Selects all lights.

  • %Camera - Selects all cameras.

  • %Image - Selects all images.

  • %Null - Selects all null objects.

  • %Bone - Selects all bone objects.


Matches any PolyMesh typed objects


Matches the ‘Objects’ virtual node. For example, in a scene with polygonal objects and lights, the ‘Objects’ node will have all of them as children nodes.

Node Name

We can select nodes by their name. Since names are not required to be unique in, this may retrieve multiple nodes.


Matches any nodes named Sphere.

Regular Expressions

Node name selections can use Javascript regular expression (regex) pattern matching to select any node names following a pattern. Currently square brackets are not permitted. Also any escaped characters must be doubly escaped. For more information on regex patterns, visit the W3Schools Reference.


Matches “SphereA” and “Sphere1” but not “Sphere”


Matches “Sphere” and “Sphere1”


Matches “Sphere”, “Sphere1”, “SphereA”, “Sphere11”, etc.


Matches “AB” and “ABAB” but not “ABABAB”


This selects all plugs of the given type. A plug changes the appearance and behavior of a node and it has associated one primitive. This selection is case sensitive.
Valid plugs are:

  • #Transform - Selects all transform plugs.

  • #Properties - Selects all properties plugs.

  • #Material - Selects all material plugs.

  • #Texture - Selects all texture plugs.


Matches all Transform plugs.


Matches all plug nodes corresponding to nodes named MySphere.


This gets operators within a given plug. The operator property must be given as a camelCase name of the label.
Since operators are returned, we can easily extract information from the operators.
To get an attribute value from an operator in a plug, we use:


Here we use ctx to select nodes that match the PlugType and Property, and we use the get function to obtain the actual property value.


Matches the depth property of the Box operator within all PolyMesh plugs.


Matches the translation property of the transform node of nodes called ‘MyBox’ and returns the translation of the first match.


This selects operators within a given plug if its the value of one of its attributes or schema objects equals the given value.


Matches all operators with the name Box within all Polymesh plugs.

Combining Selections

As we have seen above, the operator selection depends on having a plug. Other selections can be optionally combined, such as node name and type.


Matches all operators with the name ‘DirectionalLight’ that belong to a Light plug, that are on a node of type Light, with a node name matching DLight followed by any number of extra characters.

Next (Objects) Previous (Scripting(Old))