Hello,
Upon building an simple extension I wanted to make a button that would spawn Dynamic Cuboids the ones you gave as an example at core api tutorials.
error goes as follows: AttributeError: ‘NoneType’ object has no attribute ‘scene’
And the code I wrote for the extension is:
import omni.ext
import omni.ui as ui
from omni.isaac.examples.base_sample import BaseSample
import asyncio
import numpy as np
from omni.isaac.core.objects import DynamicCuboid
class MyWindow(ui.Window, BaseSample):
def init(self, title: str = None, delegate=None, **kwargs):
super().init(title, **kwargs)
self.world = None
self._world = None
self.proj_scale_model_0=None
self.proj_scale_model_1=None
self.frame.set_build_fn(self._build_window)
self._controller = None
self._articulation_controller = None
def _on_clear(self):
asyncio.ensure_future(self.clear_async())
return
def _on_usd_load(self):
stage = omni.usd.get_context().get_stage()
prim = stage.DefinePrim("/World", "Xform")
prim.GetReferences().AddReference("/home/mario/Documents/IsaacSaveFile/UR10-zavrsni_INTERIJER.usd")
return
def setup_post_load(self):
world = self.get_world()
world.scene.add(
DynamicCuboid(
prim_path="/World/random_cube",
name="fancy_cube",
position=np.array([0.3, 0.3, 0.3]),
size=np.array([0.0515, 0.0515, 0.0515]),
color=np.array([0, 0, 1.0]),
)
)
return
def _build_window(self):
with ui.ScrollingFrame():
with ui.VStack(spacing = 0, height = 0):
with ui.CollapsableFrame("USD"):
with ui.VStack(height=0):
ui.Button("USD Load", clicked_fn=lambda: clicked_usd_load())
def clicked_usd_load():
self._on_usd_load()
print("USD Loaded")
return
ui.Button("Clear", clicked_fn=lambda: clicked_clear())
def clicked_clear():
self._on_clear()
print("Viewport Cleared!")
ui.Button("Add Cube", clicked_fn=lambda: clicked_add_cube())
def clicked_add_cube():
self.setup_post_load()
print("Cube Added!")
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
print(“MyExtension startup”)
self._window = MyWindow(“Proba”, width=300, height=300)
def on_shutdown(self):
print("MyExtension shutdown")
if self._window:
self._window.destroy()
self._window = None
This problem is introduction into some other problems I had with translating core api tutorials into my own examples, I wonder where have I made an oversight.
Thank you!