Changeset View
Changeset View
Standalone View
Standalone View
doc/python_api/examples/bpy.types.Operator.5.py
| Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | class ModalOperator(bpy.types.Operator): | ||||
| def invoke(self, context, event): | def invoke(self, context, event): | ||||
| self.init_loc_x = context.object.location.x | self.init_loc_x = context.object.location.x | ||||
| self.value = event.mouse_x | self.value = event.mouse_x | ||||
| self.execute(context) | self.execute(context) | ||||
| context.window_manager.modal_handler_add(self) | context.window_manager.modal_handler_add(self) | ||||
| return {'RUNNING_MODAL'} | return {'RUNNING_MODAL'} | ||||
| # Only needed if you want to add into a dynamic menu | |||||
| def menu_func(self, context): | |||||
| self.layout.operator(ModalOperator.bl_idname, text="Modal Operator") | |||||
| # Register and add to the file selector | |||||
lichtwerk: please add the //(required to use F3 search....// part here as well | |||||
| bpy.utils.register_class(ModalOperator) | bpy.utils.register_class(ModalOperator) | ||||
| bpy.types.VIEW3D_MT_object.append(menu_func) | |||||
| # test call | # test call | ||||
| bpy.ops.object.modal_operator('INVOKE_DEFAULT') | bpy.ops.object.modal_operator('INVOKE_DEFAULT') | ||||
please add the (required to use F3 search.... part here as well