I’m writing a Python extension (in v106.3) that creates a toolbar and docks it to the top of the viewport when the extension loads. Here is the relevant snippet of code:
class MyToolBarExtension(omni.ext.IExt):
def on_startup(self, _ext_id):
self._toolbar = omni.ui.ToolBar("My ToolBar")
viewport = omni.ui.Workspace.get_window("Viewport")
if viewport is not None:
print("Viewport found, docking.")
# I get a warning that `dock_in_window` is deprecated, but the `dock_in` function it recommends doesn't seem to work at all
self._toolbar.dock_in_window("Viewport", omni.ui.DockPosition.TOP)
The problem is, even though the viewport does seem to exist by the time this on_startup
function is called (i.e. “Viewport found, docking.” prints in the console), the toolbar still doesn’t dock. However, if I reload the extension, then it docks. How do I get it to dock on load?
I’ve tried the following variants:
class MyToolBarExtension(omni.ext.IExt):
def on_startup(self, _ext_id):
self._toolbar = omni.ui.ToolBar("My ToolBar")
self._toolbar.deferred_dock_in("Viewport")
That code never results in the toolbar docking, even when reloading the extension. Same with the following:
class MyToolBarExtension(omni.ext.IExt):
def on_startup(self, _ext_id):
self._toolbar = omni.ui.ToolBar("My ToolBar")
omni.ui.Workspace.set_window_created_callback(self.on_window_created)
def on_window_created(self, window):
if window.title == "Viewport":
print("Viewport created, now docking.")
self._toolbar.dock_in_window("Viewport", omni.ui.DockPosition.TOP)
The viewport seems to generally be created by the time this extension loads, so the if statement there never triggers.
Any thoughts? Thanks!