How to load a usd as stage in extension?

Isaac Sim Version

4.5.0

Operating System

Windows 11

GPU Information

  • Model: NVIDIA RTX 4090 16GB
  • Driver Version: 537.58

Topic Description

Detailed Description

I am trying to load an usd file as a stage and then use the world to add task for a simulation, I use " stage = omni.usd.get_context().open_stage(usd_file_path, None)" and it logs error of AttributeError: ‘World’ object has no attribute ‘_scene’

Steps to Reproduce

  1. Create an extension in extension/examples

  2. In the ui file, in function setup_scene(self):
    usd_file_path = ‘path_to_any_usd’
    stage = omni.usd.get_context().open_stage(usd_file_path, None)
    world = self.get_world()
    world.reset()

  3. Press the load button

Error Messages

025-04-08 09:19:00 [2,643,850ms] [Error] [asyncio] Task exception was never retrieved
future: <Task finished name=‘Task-26496’ coro=<BaseSampleUITemplate._on_load_world.._on_load_world_async() done, defined at c:/nvidia_coe/isaacsim/exts/isaacsim.examples.interactive/isaacsim/examples/interactive/base_sample/base_sample_extension.py:107> exception=AttributeError(“‘World’ object has no attribute ‘_scene’”)>
Traceback (most recent call last):
File “c:/nvidia_coe/isaacsim/exts/isaacsim.examples.interactive/isaacsim/examples/interactive/base_sample/base_sample_extension.py”, line 108, in _on_load_world_async
await self._sample.load_world_async()
File “c:/nvidia_coe/isaacsim/exts/isaacsim.examples.interactive/isaacsim/examples/interactive/base_sample/base_sample.py”, line 46, in load_world_async
await self._world.reset_async()
File “c:/nvidia_coe/isaacsim/exts/isaacsim.core.api/isaacsim/core/api/world/world.py”, line 503, in reset_async
await self.reset_async_no_set_up_scene(soft=soft)
File “c:/nvidia_coe/isaacsim/exts/isaacsim.core.api/isaacsim/core/api/world/world.py”, line 463, in reset_async_no_set_up_scene
self._scene._finalize(self.physics_sim_view)
AttributeError: ‘World’ object has no attribute ‘_scene’

What I’ve Tried

I tried :
def setup_scene(self):
usd_file_path = ‘F:/LamTran/Integrate/warehouse.usd’
stage = omni.usd.get_context().open_stage(usd_file_path, None)
world = self.get_world()
world.reset()
return

Related Issues

(If you’re aware of any related issues or forum posts, please link them here)

Additional Context

(Add any other context about the problem here)

Hi @tran.nguyenquanglam! If you want to load a USD as a stage in extension, please use open_stage_async and ensure_future. For example:

async def create_scenario(self):
    await omni.usd.get_context().open_stage_async("my.usd")

asyncio.ensure_future(self.create_scenario())

In the Isaac Sim 5 exts folder, you can find some examples, such as ./isaacsim.sensors.physics.examples/isaacsim/sensors/physics/examples/imu_sensor.py

Thank you Zhengwang,
I did solve it by using open_state_async. But I did realize that what cause the error before was, there was an empty stage open before, then I tried to open my usd file as stage.
Solved it by openning the usd stage instead of an empty stage in the BaseSample class

async def load_world_async(self):
        await open_stage_async(self._usd_file_path)
        self._world = World(**self._world_settings)
1 Like