2
$\begingroup$

How do I detect if the active tool changes? I need to update a property when the active tool changes. This seems to work ,but you have to change modes for it to be detected.

import bpy
from bpy.app.handlers import persistent


@persistent
def toolUpdated(scene):  
    tools = bpy.context.workspace.tools
    active_tool = tools.from_space_view3d_mode(bpy.context.mode).idname

    depsgraph = bpy.context.evaluated_depsgraph_get()

    for update in depsgraph.updates:
        if update.id.original != active_tool:            
            print(active_tool)        


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

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

if __name__ == "__main__":
    register()
$\endgroup$
1
  • $\begingroup$ tools.from_space_view3d_mode(bpy.context.mode) can be None $\endgroup$
    – batFINGER
    Jan 25, 2020 at 19:02

0

You must log in to answer this question.

Browse other questions tagged .