How can I edit a usd prim hierarchy without loading it to stage?

Isaac Sim Version

4.5.0

Operating System

Ubuntu 22.04

Topic Description

Detailed Description

I am using SceneBlox. I generated the USD. I know the path to the generated USDs. I want to load the generated USDs into my extension. But using add_reference_stage() or the bellow callback does not work.

    def _on_load_asset_btn(self):
        create_new_stage()
        stage = omni.usd.get_context().get_stage()
        default_prim = UsdGeom.Xform.Define(stage, Sdf.Path("/World")).GetPrim()
        stage.SetDefaultPrim(default_prim)

        usd_path = self.get_selected_usd_absolute_path()
        if usd_path:
            print(f"[INFO] Loading USD file: {usd_path}")
            xform = UsdGeom.Xform.Define(
                stage, Sdf.Path("/World").AppendPath("import_asset")
            )
            prim = xform.GetPrim()
            prim.GetReferences().AddReference(str(usd_path))

        else:
            print("[ERROR] No valid USD file selected")

        return

I checked the structure of the generated USD and saw something like:

/World
/Environment
/physicsScene

so I move all of them under /defaultPrim

/defaultPrim
  /World
  /Environment
  /physicsScene

then both add_reference_to_stage() and my callback work.

So is there any ways that I can automate this post-processing?

Error Messages

[INFO] Selected USD file: generated_1.usd
[INFO] Loading USD file: path_to/generated_1.usd
2025-08-04 03:50:17 [7,464,604ms] [Warning] [omni.usd] Warning: in _ReportErrors at line 2890 of /builds/omniverse/usd-ci/USD/pxr/usd/usd/stage.cpp -- In </World/import_asset>: Unresolved reference prim path @path_to/generated_1.usd@<defaultPrim> introduced by @anon:0x7536761db610:World21.usd@</World/import_asset> (recomposing stage on stage @anon:0x7536761db610:World21.usd@ <0x753681c3fe30>)

2025-08-04 03:50:17 [7,464,606ms] [Warning] [omni.usd] Warning: in AppendProperty at line 858 of /builds/omniverse/usd-ci/USD/pxr/usd/sdf/path.cpp -- Can only append a property 'physics:rigidBodyEnabled' to a prim path (/)

@hslktestmail i am just another user and have not used SceneBlox, but perhaps adding a separate process to define the defaultprim programmatically of the USD you are wanting to reference before calling add_reference_stage?

here’s another suggestion from the mods/devs in the context of SDG that may also be relevant:

Thank you for your suggestion but it does not work in my case, I think.

The workaround is to open the USD and set that default prim. But in my case the extension user want more convenience, so …

    def _on_load_asset_btn(self):
        # create_new_stage()
        # stage = omni.usd.get_context().get_stage()
        # default_prim = UsdGeom.Xform.Define(stage, Sdf.Path("/World")).GetPrim()
        # stage.SetDefaultPrim(default_prim)

        usd_path = self.get_selected_usd_absolute_path()
        if usd_path:
            # print(f"[INFO] Loading USD file: {usd_path}")
            # xform = UsdGeom.Xform.Define(
            #     stage, Sdf.Path("/World").AppendPath("imported_asset")
            # )
            # prim = xform.GetPrim()
            # prim.GetReferences().AddReference(str(usd_path))
            usd_open(usd_path=usd_path)
            # default_prim = ""
            # if not usd_stage.HasDefaultPrim():
            #     top_level_prims = usd_stage.GetPseudoRoot().GetChildren()
            #     if len(top_level_prims) == 0:
            #         raise ValueError(f"Asset at {usd_path} appears to be empty")
            #     default_prim = str(top_level_prims[0].GetPath())
            # print(usd_path, default_prim)

        else:
            print("[ERROR] No valid USD file selected")

        return


@rep.utils.ReplicatorWrapper
def usd_open(usd_path: str):
        usd_stage = Usd.Stage.Open(usd_path)
        print(f"[INFO] Opening USD file: {usd_stage}")

with the decorator

[INFO] Selected USD file: generated_1.usd
2025-08-04 07:46:30 [2,705,581ms] [Error] [omni.ui.python] ErrorException: 
	Error in 'pxrInternal_v0_22__pxrReserved__::UsdStage::Open' at line 893 in file /builds/omniverse/usd-ci/USD/pxr/usd/usd/stage.cpp : 'Failed to open layer @/scene_blox/generated_scene/generated_1.usd@'

At:
/isaac-sim-4.5.0/project/ROAS_ext/ROAS_SceneGen/ROAS_python/ui_builder.py(1407): usd_open
/isaac-sim-4.5.0/extscache/omni.replicator.core-1.11.35+106.5.0.lx64.r.cp310/omni/replicator/core/scripts/utils/utils.py(717): __init__
/mnt/nvme/huy/Documents/isaac-sim-4.5.0/extscache/omni.replicator.core-1.11.35+106.5.0.lx64.r.cp310/omni/replicator/core/scripts/utils/utils.py(688): __call__
/isaac-sim-4.5.0/project/ROAS_ext/ROAS_SceneGen/ROAS_python/ui_builder.py(1390): _on_load_asset_btn
/isaac-sim-4.5.0/exts/isaacsim.gui.components/isaacsim/gui/components/element_wrappers/ui_widget_wrappers.py(886): _on_clicked_fn_wrapper

without the decorator

2025-08-04 07:49:34 [2,889,813ms] [Error] [omni.ui.python] ErrorException: 
	Error in 'pxrInternal_v0_22__pxrReserved__::UsdStage::Open' at line 893 in file /builds/omniverse/usd-ci/USD/pxr/usd/usd/stage.cpp : 'Failed to open layer @/scene_blox/generated_scene/generated_0.usd@'

At:
/isaac-sim-4.5.0/path_to/ui_builder.py(1406): usd_open
/isaac-sim-4.5.0/path_to/ui_builder.py(1390): _on_load_asset_btn
/isaac-sim-4.5.0/exts/isaacsim.gui.components/isaacsim/gui/components/element_wrappers/ui_widget_wrappers.py(886): _on_clicked_fn_wrapper

The solution for my case is in this link: When I use Python to open .usd, it was empty and lost all the content

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.