I have made an extension for Create to automatically load USD levels as layers. The idea is when the extension has a variable set to true, it will go ahead and load in the requested USD’s.
One issue i am having with this is when i set the extension to automatically load, it does nothing on the first launch of create, but it works if i disable it, then re-enable it. The code below. I’m having another issue with the loading of the layers but i will make another topic for that.
@michaelbaggott Do you mean the extension is loaded on startup, but your logic is not executed until you secondly switched it off and on? Could you show me your complete code about how those sublayers are initialized? I think it’s issue of your code initialization.
Yes the extension is turned on, but when Create first opens the code is not executed and the extension window doesn’t appear on screen until i switch it off then on again after openingf Create
Did you see any errors from the console window? Can you paste the config/extension.toml also here? Just to make sure that “omni.ui” and “omni.usd” is in your dependency list of your extension. Or if you can, it’s better to package the minimum extension that could repro it.
Thanks so much Rozhang, no errors in the console window. Dependencies are not listed in the toml file but i can add them, it seems to work without them though when i manually turn it off and on
@michaelbaggott I am afraid you’d have to live with it for now or you can add a menu item to Window like the following, as Create has window management that will hide those non-builtin ones at startup. You can now enable/disable your window from window menu.
import omni.ext
import omni.ui as ui
import omni.kit
# Functions and vars are available to other extension as usual in python: `example.python_ext.some_public_function(x)`
def some_public_function(x: int):
print(f"[example.python_ext] some_public_function was called with {x}")
return x ** x
# Any class derived from `omni.ext.IExt` in top level module (defined in `python.modules` of `extension.toml`) will be
# instantiated when extension gets enabled and `on_startup(ext_id)` will be called. Later when extension gets disabled
# on_shutdown() is called.
class HelloPythonExtension(omni.ext.IExt):
# ext_id is current extension id. It can be used with extension manager to query additional information, like where
# this extension is located on filesystem.
def on_startup(self, ext_id):
print("[example.python_ext] HelloPythonExtension startup")
self._window_title = "My Window"
self._menu_path = "Window/My Window"
self._window = None
try:
self._menu = omni.kit.ui.get_editor_menu().add_item(
self._menu_path, self.show_window, toggle=True, value=False
)
except Exception as e:
self._menu = None
def on_shutdown(self):
print("[example.python_ext] HelloPythonExtension shutdown")
if self._window:
self._window.set_visibility_changed_fn(None)
self._window = None
self._menu = None
def build_window(self):
self._window = ui.Window(self._window_title, width=300, height=300, visible=True)
self._window.set_visibility_changed_fn(self._visibility_changed_fn)
with self._window.frame:
with ui.VStack():
ui.Label("Automatically open file")
def on_click():
print(f"click")
ui.Button("Click Me", clicked_fn=lambda: on_click())
def show_window(self, menu, value):
if not self._window:
self.build_window()
elif self._window:
self._window.visible = value
def _visibility_changed_fn(self, value):
if self._menu:
omni.kit.ui.get_editor_menu().set_value(self._menu_path, value)