Isaac Sim | OmniGraph | Python API - Make array

Hello,

We are trying to programmatically use a make array (ConstructArray), but we are unable to set anything which is not input0.

Error:

2023-06-04 13:09:54 [1,965,188ms] [Error] [omni.kit.app.plugin] [py stderr]: OmniGraphError: Failed trying to look up attribute with (/nakai_container/MovementGraph/velocity_command_duplicator.inputs:input1, node=None, graph=None)

At:
  /home/amram/.local/share/ov/pkg/isaac_sim-2022.2.1/kit/exts/omni.graph/omni/graph/core/_impl/object_lookup.py(404): __attribute_from_info
  /home/amram/.local/share/ov/pkg/isaac_sim-2022.2.1/kit/exts/omni.graph/omni/graph/core/_impl/object_lookup.py(411): attribute
  /home/amram/.local/share/ov/pkg/isaac_sim-2022.2.1/kit/exts/omni.graph/omni/graph/core/_impl/controller.py(649): _process_set_value
  /home/amram/.local/share/ov/pkg/isaac_sim-2022.2.1/kit/exts/omni.graph/omni/graph/core/_impl/controller.py(656): <listcomp>
  /home/amram/.local/share/ov/pkg/isaac_sim-2022.2.1/kit/exts/omni.graph/omni/graph/core/_impl/controller.py(656): _process_set_values
  /home/amram/.local/share/ov/pkg/isaac_sim-2022.2.1/kit/exts/omni.graph/omni/graph/core/_impl/controller.py(1031): __do_the_edits
  /home/amram/.local/share/ov/pkg/isaac_sim-2022.2.1/kit/exts/omni.graph/omni/graph/core/_impl/controller.py(1038): __edit

Reproduction script:

import omni.graph.core as og

keys = og.Controller.Keys

og.Controller.edit(
    {"graph_path": "/nakai_container/MovementGraph", "evaluator_name": "execution"},
    {
        keys.CREATE_NODES: [
            ("velocity_command_duplicator", "omni.graph.nodes.ConstructArray"),
        ],
        keys.SET_VALUES: [
            ("velocity_command_duplicator.inputs:arraySize", 4),           
            ("velocity_command_duplicator.inputs:arrayType", "double[]"),
            ("velocity_command_duplicator.inputs:input0",  1),
            ("velocity_command_duplicator.inputs:input1",  2),
            ("velocity_command_duplicator.inputs:input2",  3),
            ("velocity_command_duplicator.inputs:input3",  4),
        ]
    },
)

In the GUI, there is the plus button for adding inputs, but how can it be done via the python api?

Hi @omers - It seems like the script is not able to find the attribute for the input1 of the velocity_command_duplicator node. This error could be caused by the node not being created properly before trying to set its input values.

To fix this issue, you can try splitting the creation and setting of values into two separate calls to the og.Controller.edit() method. Here’s the modified script:

import omni.graph.core as og

keys = og.Controller.Keys

Create the node first

og.Controller.edit(
{“graph_path”: “/nakai_container/MovementGraph”, “evaluator_name”: “execution”},
{
keys.CREATE_NODES: [
(“velocity_command_duplicator”, “omni.graph.nodes.ConstructArray”),
],
},
)

Set the input values for the created node

og.Controller.edit(
{“graph_path”: “/nakai_container/MovementGraph”, “evaluator_name”: “execution”},
{
keys.SET_VALUES: [
(“velocity_command_duplicator.inputs:arraySize”, 4),
(“velocity_command_duplicator.inputs:arrayType”, “double”),
(“velocity_command_duplicator.inputs:input0”, 1),
(“velocity_command_duplicator.inputs:input1”, 2),
(“velocity_command_duplicator.inputs:input2”, 3),
(“velocity_command_duplicator.inputs:input3”, 4),
],
},
)

Let us know if it works or not.

@rthaker Thanks for the detailed response.

First part creating the node working, second part trying to edit it throws the following exception:

2023-06-18 13:47:47 [270,818ms] [Error] [omni.kit.app.plugin] [py stderr]: OmniGraphError: Failed to wrap graph in node given {'graph_path': '/nakai_container/MovementGraph', 'evaluator_name': 'execution'}

At:
  /home/amram/.local/share/ov/pkg/isaac_sim-2022.2.1/kit/exts/omni.graph/omni/graph/core/_impl/graph_controller.py(172): __create_graph
  /home/amram/.local/share/ov/pkg/isaac_sim-2022.2.1/kit/exts/omni.graph/omni/graph/core/_impl/graph_controller.py(106): create_graph
  /home/amram/.local/share/ov/pkg/isaac_sim-2022.2.1/kit/exts/omni.graph/omni/graph/core/_impl/controller.py(939): __do_the_edits
  /home/amram/.local/share/ov/pkg/isaac_sim-2022.2.1/kit/exts/omni.graph/omni/graph/core/_impl/controller.py(1038): __edit
  /home/amram/.local/share/ov/pkg/isaac_sim-2022.2.1/kit/exts/omni.graph/omni/graph/core/_impl/controller.py(878): edit
  /tmp/carb.mOqQgg/script_1687096067.py(14): <module>

Hi @omers - Can you try this other script? if it doesn’t work then I will bring this issue to the Omnigraph experts.

import omni.graph.core as og

keys = og.Controller.Keys

og.Controller.edit(
    {"graph_path": "/nakai_container/MovementGraph", "evaluator_name": "execution"},
    {
        keys.CREATE_NODES: [
            ("velocity_command_duplicator", "omni.graph.nodes.ConstructArray"),
        ],
        keys.SET_VALUES: [
            ("velocity_command_duplicator.inputs:arraySize", 4),
            ("velocity_command_duplicator.inputs:arrayType", "double[]"),
            ("velocity_command_duplicator.inputs:input0", 1),
        ]
    },
)

# Create a separate node or function to set the values of the other array elements
for i in range(1, 4):
    og.Controller.edit(
        {"graph_path": "/nakai_container/MovementGraph", "evaluator_name": "execution"},
        {
            keys.SET_VALUES: [
                (f"velocity_command_duplicator.inputs:input{i}", i + 1),
            ]
        },
    )

I am also experiencing the same issue. When creating a MakeArray omnigraph node using a Python script, the inputs value is not being added, and the problem was not resolved even when I used the suggested method. I would like to know if there is another way.

    og.Controller.Keys.SET_VALUES: [
        ("DifferentialController.inputs:wheelDistance", 0.53342),
        ("DifferentialController.inputs:wheelRadius", 0.24),
        ("MakeArray.inputs:arraySize", 2),
        ("MakeArray.inputs:arrayType", "token[]"),
        ("MakeArray.inputs:input0", "left_wheel"),
        ("MakeArray.inputs:input1", "right_wheel"),
        ("ArticulationController.inputs:targetPrim", "/World/Robot"),
        ("ArticulationController.inputs:usePath", False),
    ],