vrNodeService

class vrNodeService

(Inherits vrBaseService)

A service that provides helper functions for working with vrdNodes.

class TraverseChoice

Defines the choice for the next traverse iteration.

Continue

Move on to the next (either child or sibling) node.

Skip

Skip all child nodes and continue with next sibling.

Quit

Terminate the traversal.

Functions

vrNodeService.clearFindCache()

Clears the find cache.

The find cache is an internal cache structure to speed up the execution of the findNode(s) command. After changing the scenegraph the findcache is no longer valid and needs to be rebuilt! vrNodeService.clearFindCache() Invalidates the cache so all find calls will no longer use the cache resulting in longer search times.

vrNodeService.cloneNodes(nodes)

Clone a list of nodes from the scene graph.

Parameters:nodes (List[vrdNode]) – The list of nodes to clone.
Returns:A list of cloned nodes.
Return type:List[vrdNode]
vrNodeService.findNode(name, wildcard=False, includeComponents=False, root=vrdNode(), caseSensitive=True)

Finds the node via name.

Parameters:
  • name (string) – The name of the node.
  • wildcard (bool) – Use wildcard matching.
  • includeComponents (bool) – Search below shells.
  • root (vrdNode) – The search will start at this node.
  • caseSensitive (bool) – If set to False, search case insensitive
Returns:

The found node.

Return type:

vrdNode

vrNodeService.findNodes(name, wildcard=False, includeComponents=False, root=vrdNode(), caseSensitive=True)

Finds a list of nodes depending on their name.

Be aware that this is a costly operation. To speed up use the function vrNodeService.initFindCache() once your scenegraph structure does no longer change.

Parameters:
  • name (string) – The name of the node.
  • wildcard (bool) – Use wildcard matching.
  • includeComponents (bool) – Search below shells.
  • root (vrdNode) – The search will start at this node
  • caseSensitive (bool) – If set to False, search case insensitive
Returns:

The found nodes.

Return type:

List[vrdNode]

vrNodeService.findNodes(names, wildcard=False, includeComponents=False, root=vrdNode(), caseSensitive=True)

Finds a list of nodes depending on a list of names.

This function will return all nodes that match any of the names in the list.

Be aware that this is a costly operation. To speed up use the function vrNodeService.initFindCache() once your scenegraph structure does no longer change.

Parameters:
  • names (List[string]) – The list of node names.
  • wildcard (bool) – Use wildcard matching.
  • includeComponents (bool) – Search below shells.
  • root (vrdNode) – The search will start at this node
  • caseSensitive (bool) – If set to False, search case insensitive
Returns:

The found nodes.

Return type:

List[vrdNode]

vrNodeService.findNodes(function, options=vrdFindOptions(), root=vrdNode())

Finds a list of nodes depending on a Python matching function.

Requirements for the Python function:
- Takes exactly one vrdNode as input parameter
- Must evaluate to boolean.
def findGeometry(node):
    return node.isType(vrdGeometryNode)

vrNodeService.findNodes(findGeometry, vrdFindOptions(), vrNodeService.getRootNode())
# also works with lambdas: vrNodeService.findNodes(lambda node: node.isType(vrdGeometryNode))
Parameters:
  • function (function) – A Python function object.
  • options (vrdFindOptions) – Additional find options.
  • root (vrdNode) – The search will start at this node. If null, the scene root is used.
Returns:

The found nodes.

Return type:

List[vrdNode]

vrNodeService.findNodesWithPath(path, wildcard=False, root=vrdNode())

Finds a list of nodes depending on the node path.

The node path is the The names of the ancestor nodes and the node itself concatenated by a slash (/), e.g. “Root/Group/Geometry123”.

Parameters:
  • path (string) – The node path.
  • wildcard (bool) – Use wildcard matching.
  • root (vrdNode) – The search will start at this node.
Returns:

The found nodes.

Return type:

List[vrdNode]

vrNodeService.findNodeWithPath(path, wildcard=False, root=vrdNode())

Finds a node depending on its node path.

The node path is the The names of the ancestor nodes and the node itself concatenated by a slash (/), e.g. “Root/Group/Geometry123”.

Parameters:
  • path (string) – The node path.
  • wildcard (bool) – Use wildcard matching.
  • root (vrdNode) – The search will start at this node
Returns:

The found node.

Return type:

vrdNode

vrNodeService.findNodeWithUniquePath(uniquePath)

Find a node by its unique path. See vrdNode.getUniquePath().

Parameters:uniquePath (string) – The unique path to look for.
Returns:The node with given unique path.
Return type:vrdNode
vrNodeService.getAllNodes(root, options=vrdFindOptions())

Get all nodes in the given sub graph.

Parameters:
  • root (vrdNode) – The root node of the graph
  • options (vrdFindOptions) – Find options. By default, components are skipped
Returns:

All nodes found in the given graph

Return type:

List[vrdNode]

vrNodeService.getCloneRoot(node)

Get the top most node of a clone hierarchy.

Parameters:node (vrdNode) – The node to examine
Returns:The top most node of the clone hierarchy
Return type:vrdNode
vrNodeService.getClones(node)

Gets the clones of a given node.

Parameters:node (vrdNode) – The node to query.
Returns:A list of nodes.
Return type:List[vrdNode]
vrNodeService.getCommonParent(nodes)

Find the first equal parent for the given nodes.

Parameters:nodes (List[vrdNode]) – The nodes to examine
Returns:The first node that is parent to all given nodes
Return type:vrdNode
vrNodeService.getMaxDepth(node)

Get the maximum depth of the given graph.

Parameters:node (vrdNode) – The graph to check
Returns:The maximum depth of any sub graph
Return type:integer
vrNodeService.getNodeFromId(nodeId)

Gets a node by its identifier.

This returns a vrdNode for a given node identifier. You can convert from an old vrNodePtr to a vrdNode by taking the ID from the old node like this:

newnode = vrNodeService.getNodeFromId(oldnode.getID())
Parameters:nodeId (integer) – The node identifier
Returns:The node from identifier.
Return type:vrdNode
vrNodeService.getNodesFromIds(nodeIds)

Gets nodes from its identifiers.

Parameters:nodeIds (List[integer]) – The node identifiers.
Returns:The associated nodes.
Return type:List[vrdNode]
vrNodeService.getRootNode()

Returns the root node.

Returns:The root node.
Return type:vrdNode
vrNodeService.getSelectedNodes()

Returns a list of selected nodes.

Returns:The selected nodes.
Return type:List[vrdNode]
vrNodeService.getSelectedRootNodes()

Returns a list of selected root nodes.

Returns:The selected root nodes.
Return type:List[vrdNode]
vrNodeService.getUniqueName(name, root, recursive=True)

Get a unique name for a node.

Parameters:
  • name (string) – This name will be used to create a unique name
  • root (vrdNode) – The name should be unique in this graph
  • recursive (bool) – If False, name will only be unique for direct children of root
Returns:

A unique name

Return type:

string

vrNodeService.initFindCache()

Build up an internal cache structure to speed up execution of find commands.

Build up an internal cache structure to speed up execution of the python commands findNode and findNodes. E.g. for a scene with 10000 nodes it is about 700 times faster. Be aware that this cache is no longer valid after you have deleted or created nodes.

Note: Shell components (children of Shell geometry nodes) are not included in the cache.

Example: See also example find2.py

vrNodeService.isInSubtree(root, node)

Tells if a node is a direct or indirect child of a given root node.

Parameters:
  • root (vrdNode) – The root node.
  • node (vrdNode) – The node to check for.
Returns:

True if the given node is a direct or indirect child.

Return type:

bool

vrNodeService.removeNodes(nodes)

Removes a list of nodes from the scene graph.

Parameters:nodes (List[vrdNode]) – The list of nodes to remove.
vrNodeService.traverse(function, root=vrdNode())

Traverses a node graph and calls a Python function for each node.

Requirements for the Python function:
- Takes exactly one vrdNode as input parameter
- Must evaluate to TraverseChoice.
shells = []

def collectShells(node):
    if node.isType(vrdGeometryNode) and node.isShell():
        shells.append(node)
        return vrNodeService.TraverseChoice.Skip
    return vrNodeService.TraverseChoice.Continue

vrNodeService.traverse(collectShells, vrNodeService.getRootNode())
Parameters:
  • function (function) – A Python function object.
  • root (vrdNode) – The search will start at this node. If null, the scene root is used.
vrNodeService.unshareNodes(nodes, option=vrScenegraphTypes.KeepLocalClones)

Unshare a list of subtrees from the scene graph.

Unshare will break the connection between two nodes which share the same settings and children.

- vrScenegraphTypes::UnshareOption::UnshareAll will fully unshare all nodes in the subtree.
- vrScenegraphTypes::UnshareOption::KeepLocalClones will unshare the tree but keep the clone connections inside the subtree.
- vrScenegraphTypes::UnshareOption::KeepGlobalClones will unshare the node and implicitly shared children but will not unshare cloned children that have explicit clone connections to other nodes (inside or outside the subtree).
Parameters:

Signals

vrNodeService.nodesAdded(nodes)

This signal will be send when new nodes was added.

Parameters:nodes (List[vrdNode]) – The list of all added nodes.
vrNodeService.nodesRemoved(nodes)

This signal will be send when nodes was deleted.

Parameters:nodes (List[vrdNode]) – The list of all removed nodes.
vrNodeService.selectionChanged()

Signal is emitted when the scene tree selection has been changed.