Editing OmniGraphNode rel attributes programmatically (Python)

Isaac Sim Version

4.5.0

Operating System

Ubuntu 22.04

GPU Information

  • Model:
  • Driver Version:

Topic Description

Detailed Description

Hello,
I’m using a python script for dynamic compostion of an Isaac Sim scene from separate USD files, according to input arguments (specifically unitree_sim_isaaclab/sim_main.py at main · unitreerobotics/unitree_sim_isaaclab · GitHub ). I’d like to add support for ROS2 camera, for which I created a USD file with an Omni Graph (following the tutorial ROS 2 Cameras — Isaac Sim Documentation ). However, the problem is with setting inputs:cameraPrim attribute, as it is of type custom rel, which is probably the reason why it is not listed among other attributes (`prim_node.GetAttributes()`) and thus cannot be adjusted via prim_node.GetAttribute("inputs:cameraPrim").Set(...).
Is there a way to programmatically access/adjust external relationships of OmniGraph nodes? I searched the documentation, but could not find a clue about this particular process.
Thank you for your help

Steps to Reproduce

  1. minimal_example.txt (1.9 KB) (change extension to .py)

  2. ActionGraph.txt (1.6 KB) (change extension to .usda)

  3. `python3 minimal_example.py`

Error Messages

invalid attribute ‘inputs:cameraPrim’ on ‘OmniGraphNode’ prim </World/ActionGraph/ActionGraph/isaac_create_render_product> on stage with rootLayer @anon:0x5d8b857e0750:World0.usd@, sessionLayer @anon:0x5d8b84e62120:World0-session.usda@

Hi, sorry for the late reply. inputs:cameraPrim is a USD relationship, not an attribute. ActionGraph.usda declares
custom rel inputs:cameraPrim with relType = "target". Relationships and attributes are distinct USD concepts, so GetAttributes() and GetAttribute() will never return it. The correct discovery API is GetRelationships() /
GetRelationship().

prim = stage.GetPrimAtPath("/World/ActionGraph/ActionGraph/isaac_create_render_product")
print([r.GetName() for r in prim.GetRelationships()])
# ['inputs:cameraPrim', 'inputs:renderProductPrim']

Any of these three will set it:
1. Plain USD — closest to what you were attempting:

from pxr import Sdf
 prim.GetRelationship("inputs:cameraPrim").SetTargets([Sdf.Path("/World/Camera")])

2. The Isaac Sim helper, which does the same thing:

from isaacsim.core.nodes.scripts.utils import set_target_prims
set_target_prims(    primPath="/World/ActionGraph/ActionGraph/isaac_create_render_product", targetPrimPaths=["/World/Camera"],
 inputName="inputs:cameraPrim",
)

One caveat: it catches and prints exceptions rather than raising, so a bad path fails quietly.

3. og.Controller

import omni.graph.core as og
from pxr import Sdf

og.Controller.edit(
    "/World/ActionGraph/ActionGraph",
    {og.Controller.Keys.SET_VALUES: [
        (".../isaac_create_render_product.inputs:cameraPrim", [Sdf.Path("/World/Camera")]),]},)

The value is flexible — [Sdf.Path(p)], Sdf.Path(p), a plain "/World/Camera" string, ["/World/Camera"], and [usdrt.Sdf.Path(p)] all work.

To read it back, use the relationship, not the attribute:

prim.GetRelationship("inputs:cameraPrim").GetTargets()
# [Sdf.Path('/World/Camera')]

Closing the topic. Please open new topics if you have other questions.