I want when a user is selecting/deselecting an object to do something.

I'm working on an alignment tool (free to use) and I manage to make almost everything work.

If you select several objects and click align x or rotate x, it will align rotation/scale/dimension/move

But I can't figure out how to hook into select/deselect event so that I can automatically align objects based on what is checked.


1 Answer 1


I'm not going to claim this is the correct way; but it will work

import bpy

def _depsgraph_update(scene):

# bpy.app.handlers.depsgraph_update_post.remove(_depsgraph_update)

The other thing you can try; is listening for the active object changing - on the basis that you can't select without changing the active object. Note you won't get a change notification on undo

     key=(bpy.types.LayerObjects, "active"),
  • $\begingroup$ Thank you, I will go with the first approach $\endgroup$ Commented Aug 29, 2020 at 13:01
  • 1
    $\begingroup$ IMO not good practice to mix context and handlers. The context scene isn't necessarily the one being handled by the handler. Look over the scene objects collection. $\endgroup$
    – batFINGER
    Commented Aug 30, 2020 at 15:08

You must log in to answer this question.

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