Sdf level change notice for Python

Hi. We need to monitor layer changes in Python. But we can’t visit change paths in LayersDidChangeSentPerLayer in Python. I think we need to export such things to Python.

These are available in Python already.

Some examples:

from pxr import Sdf, Tf


def callback(notice, sender):
    print("notice: {}".format(notice))
    print("sender: {}".format(sender))


listeners = []
listeners.append(Tf.Notice.RegisterGlobally(
    Sdf.Notice.LayersDidChange,
    callback,
))
listeners.append(Tf.Notice.RegisterGlobally(
    Sdf.Notice.LayerIdentifierDidChange,
    callback,
))
listeners.append(Tf.Notice.RegisterGlobally(
    Sdf.Notice.LayerMutenessChanged,
    callback,
))

If you want to register to specific senders, use Tf.Notice.Register, for example:

Tf.Notice.Register(
    Sdf.Notice.LayersDidChangeSentPerLayer,
    callback,
    layer
)

Does that help?

See the docs for more info on the available notices:

To revoke a listener you can use the returned object, calling listener.Revoke(). So in the first example:

for listener in listeners:
    listener.Revoke()
2 Likes

Thanks @BigRoyNL@xnie’s request is to expose the contents of Sdf.Notice.LayersDidChange in its Python binding, particularly, its changes in https://github.com/PixarAnimationStudios/OpenUSD/blob/v23.11/pxr/usd/sdf/notice.h#L73, which isn’t exposed in https://github.com/PixarAnimationStudios/OpenUSD/blob/release/pxr/usd/sdf/wrapNotice.cpp, which would require Python bindings to https://github.com/PixarAnimationStudios/OpenUSD/blob/release/pxr/usd/sdf/changeList.h . I can’t remember if there was a specific reason that SdfChangeList content isn’t exposed to Python though.