2 from bpy.props import *
5 class ModalOperator(bpy.types.Operator):
6 '''Move an object with the mouse, example.'''
7 bl_idname = "object.modal_operator"
8 bl_label = "Simple Modal Operator"
10 first_mouse_x = IntProperty()
11 first_value = FloatProperty()
13 def modal(self, context, event):
14 if event.type == 'MOUSEMOVE':
15 delta = self.first_mouse_x - event.mouse_x
16 context.object.location.x = self.first_value + delta * 0.01
18 elif event.type == 'LEFTMOUSE':
21 elif event.type in ('RIGHTMOUSE', 'ESC'):
22 context.object.location.x = self.first_value
25 return {'RUNNING_MODAL'}
27 def invoke(self, context, event):
29 context.window_manager.modal_handler_add(self)
30 self.first_mouse_x = event.mouse_x
31 self.first_value = context.object.location.x
32 return {'RUNNING_MODAL'}
34 self.report({'WARNING'}, "No active object, could not finish")
38 if __name__ == "__main__":
39 bpy.ops.object.modal_operator()