2
$\begingroup$

I would like to check mesh for any modifications in Scripting API in mesh topology, such as adding or deleting vertices/faces. Is there a callback or function that works for this purpose?

$\endgroup$

1 Answer 1

7
$\begingroup$

Yes, you can use Depsgraph and handlers (depsgraph_update_post/pre) for that. For example,

import bpy

def mesh_change_listener(scene, depsgraph):
    # check if we need to iterate through updates at all
    if not depsgraph.id_type_updated('MESH'):
        return

    for update in depsgraph.updates:
        if isinstance(update.id, bpy.types.Mesh):
            print('Mesh \"{}\" updated.'.format(update.id.name))
            do_your_stuff(update.id)


if __name__ == '__main__':
    bpy.app.handlers.depsgraph_update_post.append(mesh_change_listener)
$\endgroup$
1
  • $\begingroup$ But if we subscribe to bpy.types.Object with msgbus, how do we retrieve the knowledge which object exactly got updated? $\endgroup$
    – D. Skarn
    May 9, 2020 at 10:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .