Detecting when a bone has been added to a new bone layer

Hello, I’m trying to capture an event when a bone is assigned to a new bone layer in an Armature. This code works, but not initially. No updates happen until another bone layer is created or the bone is removed from the layer. Can anyone help me to detect when the new bone layer is created? Thank you!

import bpy
from bpy.app.handlers import persistent

@persistent
def depsgraphUpdatePost(scene, depsgraph):
    for update in depsgraph.updates:
        print("update.id",update.id)
    return

def register():
    bpy.app.handlers.depsgraph_update_post.append(depsgraphUpdatePost)

def unregister():
    bpy.app.handlers.depsgraph_update_post.remove(depsgraphUpdatePost)

if __name__ == "__main__":
    register()

Since you’re printing all depsgraph updates and adding a bone to a layer isn’t triggering that, I guess adding a bone to a layer doesn’t update the depsgraph. That’s honestly surprising. I suppose you could always force a depsgraph update on a timer or something, but I think you’re out of luck if that code doesn’t work. There’s no way to change the depsgraph triggers.

Just to clarify - nothing prints (your function doesn’t run) when you add a bone to a layer?

1 Like

Thank you for the reply. Yes, your summary is correct. It is confirmed to be a bug in adding Bones to layers in Edit Mode that has a fix coming soon:
https://developer.blender.org/T101046

Any ideas on how to keep track of changes to an Armature’s bone layers?