Is there a way to know with python if the user has activated the Rotate or grab mode ( R key or G key) for a pose bone ?
Thanks
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityDetect specific operator is triggered
import bpy
# background detection modal, self-destruct when open a new blend file, switch workspace, switch to quadviews
class XX(bpy.types.Operator):
bl_idname = "view3d.xx_modal_operator"
bl_label = "XX Modal View3D Operator"
INSTANCE = None
HANDLE = None
@classmethod
def modal_fin(cls):
try:
cls.INSTANCE = None
bpy.types.SpaceView3D.draw_handler_remove(cls.HANDLE, 'WINDOW')
cls.HANDLE = None
print(" modal finished")
except:
pass
def modal(self, context, event):
if context.area is None or context.space_data.region_quadviews:
self.__class__.modal_fin()
return {'CANCELLED'}
# if event.type in {'ESC'}:
# self.__class__.modal_fin()
# return {'CANCELLED'}
for kc in context.window_manager.keyconfigs:
for km in kc.keymaps:
operator = km.keymap_items.match_event(event)
if operator and operator.active:
if operator.idname == "transform.translate":
print("When transform.translate is triggered, this message will be displayed. But when this message displayed, transform.translate is not necessarily triggered")
print(operator.name, operator.idname)
return {'PASS_THROUGH'}
def invoke(self, context, event):
cls = self.__class__
if cls.HANDLE is not None:
self.report({'WARNING'}, "Abort, modal already running.")
return {'CANCELLED'}
if context.area.type == 'VIEW_3D':
cls.INSTANCE = self
cls.AREA = context.area
cls.HANDLE = bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_PIXEL')
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
else:
self.report({'WARNING'}, "View3D not found, cannot run operator")
return {'CANCELLED'}
def draw():
try:
# if open a new file, it cannot access the INSTANCE
ins = XX.INSTANCE
except:
XX.modal_fin()
def register():
bpy.utils.register_class(XX)
def unregister():
bpy.utils.unregister_class(XX)
if __name__ == "__main__":
register()