Special Data Type Examples#

This file contains example usage for all of the AutoNode special data types. For access to the other types of examples see AutoNode Examples.

bundle#

import inspect

import omni.graph.core as og
import omni.graph.core.types as ot

@og.create_node_type
def autonode_bundle(bundle: ot.bundle, added: ot.int) -> ot.bundle:
    """Takes in a bundle value and outputs a bundle containing everything in the input bundle plus a count
    of "added" extra integer members named "added_0", "added_1", etc. Use the special value "added = 0" to
    indicate that the bundle should be cleared.
    The types of both inputs and the return value are og.BundleContents. When put into Fabric the bundle is
    stored as a data bucket and in USD it is represented as a target or reference to a prim when connected.

    Note how, since AutoNode definitions do not have direct access to the node, the inspect module must be
    used to get at it in order to construct an output bundle.
    """
    frame = inspect.currentframe().f_back
    node = frame.f_locals.get("node")
    context = frame.f_locals.get("context")
    result = og.BundleContents(context, node, "outputs_out_0", read_only=False, gpu_by_default=False)
    result.clear()
    if bundle.valid:
        result.bundle = bundle

    if added > 0:
        first_index = result.size
        for index in range(added):
            result.bundle.create_attribute(f"added_{index + first_index}", og.Type(og.BaseDataType.INT))

    return result

execution#

import omni.graph.core as og
import omni.graph.core.types as ot

@og.create_node_type
def autonode_execution(first_trigger: ot.execution, second_trigger: ot.execution) -> ot.execution:
    """Takes two execution pins and triggers the output only when both of them are enabled.
    The types of both inputs and the return value are Python ints as Python does not distinguish between
    different precision levels. When put into Fabric and USD the values are stored as 32-bit precision
    integer values.
    """
    if first_trigger == og.ExecutionAttributeState.ENABLED and second_trigger == og.ExecutionAttributeState.ENABLED:
        return og.ExecutionAttributeState.ENABLED
    return og.ExecutionAttributeState.DISABLED

objectId#

import omni.graph.core as og
import omni.graph.core.types as ot

@og.create_node_type
def autonode_objectid(first_value: ot.objectid, second_value: ot.objectid) -> ot.objectid:
    """Takes in two objectId values and outputs the larger of them.
    The types of both inputs and the return value are Python ints as Python does not distinguish between
    different precision levels or signs. When put into Fabric and USD the values are stored as 64-bit
    unsigned integer values.
    """
    return first_value if first_value > second_value else second_value

objectId[]#

import numpy as np
import omni.graph.core as og
import omni.graph.core.types as ot

@og.create_node_type
def autonode_objectidarray(first_value: ot.objectidarray, second_value: ot.objectidarray) -> ot.objectidarray:
    """Takes in two arrays of object IDs and returns an array containing the largest of each element.
    The types of both inputs and the return value are numpy.ndarray(shape=(N,), dtype=numpy.uint64) where
    "N" is the size of the array determined at runtime.
    """
    return np.maximum(first_value, second_value)

target#

import omni.graph.core as og
import omni.graph.core.types as ot
from usdrt import Sdf

@og.create_node_type
def autonode_target(target_values: ot.target) -> ot.target:
    """Takes in target values and outputs the targets resulting from appending "TestChild" to the target.
    The types of both inputs and the return value are list[usdrt.Sdf.Path]. Unlike most other array types this
    is represented as a list rather than a numpy array since the value type is not one supported by numpy.
    When put into Fabric the value is stored as an SdfPath token, while USD uses the native rel type.
    """
    return [target.AppendPath("Child") for target in target_values]