Using .subscribe_to_layer_muteness_events() to only run some script once a layer is muted

Hi, how do I go about using “subscribe_to_layer_muteness_events” method of omni.usd.Layers or omni.kit.usd.layers? (Using USD Composer 2023.2.0 w kit 105.1)
Will it enable me to run specific code only once self.Stage.MuteAndUnmuteLayers has completed its muting and unmuting?

I have multiple layers imported to my stage with a “SaveState” string in their name. My USD Composer extension allows me to only unmute 1 such layer at a time while muting the other layers. It does that through selecting ui.Checkboxes. It also makes that selected unmuted layer the Authoring layer. When I deselect that layer in my extension, it becomes muted and the Root layer is back to being the Authoring layer.

working correctly on the 1st selection:

The issue I’m having is when I have a non-Root layer selected, unmuted and set as the Authoring layer and I select another SaveState layer’s checkbox, the muting/unmuting is handled correctly but the newly selected SaveState layer isn’t set as the Authoring layer, but the Root layer is:

I’ve temporarily handled it disabling/graying-out all non-selected SaveState checkboxes thus making the user deselect the currently selected checkbox to select a new one and that works fine:
image

I’ve tried using asyncio to wait for muting/unmuting to be completed, to no results.

Hence my question about using “subscribe_to_layer_muteness_events”:
https://docs.omniverse.nvidia.com/kit/docs/kit-sdk/latest/source/extensions/omni.usd/docs/index.html

I’ve tried:

def on_events(self, e: carb.events.IEvent):
        carb.log_error("EVENT")
        carb.log_error(e)

def on_startup(self, ext_id):
        <<my code>>
        layers = omni.usd.Layers(omni.usd.get_context())
        layers.subscribe_to_layer_muteness_events(self.on_events) 

This gives me:

 [Warning] [omni.usd._impl.layer_legacy] omni.usd.Layers.subscribe_to_layer_muteness_events IS DEPRECATED AND NOT FUNCTIONAL ANYMORE!!! Please update to omni.kit.usd.layers for new layers interface.

Also the on_events function never gets triggered.

So when I try:

import omni.kit.usd.layers as layers

def on_events(self, e: carb.events.IEvent):
        carb.log_error("EVENT")
        carb.log_error(e)

def on_startup(self, ext_id):
        <<my code>>
        layers.subscribe_to_layer_muteness_events(self.on_events) 

I get:

[Error] [carb.scripting-python.plugin] AttributeError: module 'omni.kit.usd.layers' has no attribute 'subscribe_to_layer_muteness_events'

Am I going about using subscribe_to_layer_muteness_events correctly?

1 Like