# Sdf level change notice for Python

**URL:** <https://forum.aousd.org/t/sdf-level-change-notice-for-python/1030>\
**Category:** USD\
**Created:** [December 7, 2023, 2:10am UTC](https://forum.aousd.org/t/sdf-level-change-notice-for-python/1030 "2023-12-07T02:10:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xnie](https://avatars.discourse-cdn.com/v4/letter/x/b9e5f3/32.png) [@xnie](https://forum.aousd.org/u/xnie)\
**Post date:** [December 7, 2023, 2:10am UTC](https://forum.aousd.org/t/sdf-level-change-notice-for-python/1030/1 "2023-12-07T02:10:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BigRoyNL](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/bigroynl/32/413_2.png) [@BigRoyNL](https://forum.aousd.org/u/BigRoyNL)\
**Post date:** [December 7, 2023, 9:20am UTC](https://forum.aousd.org/t/sdf-level-change-notice-for-python/1030/2 "2023-12-07T09:20:32Z")

</div>

These are available in Python already.

Some examples:

```python
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:

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

```

Does that help?

See the docs for more info on the available notices:

- [`Sdf.Notice`](https://openusd.org/dev/api/class_sdf_notice.html)
- [`Usd.Notice`](https://openusd.org/dev/api/class_usd_notice.html)

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

```python
for listener in listeners:
    listener.Revoke()

```

---

<div class="post-metadata">

**Author:** ![asluk](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/asluk/32/771_2.png) [@asluk](https://forum.aousd.org/u/asluk)\
**Post date:** [December 8, 2023, 3:08am UTC](https://forum.aousd.org/t/sdf-level-change-notice-for-python/1030/3 "2023-12-08T03:08:14Z")

</div>

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](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](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](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.
