Changeset View
Changeset View
Standalone View
Standalone View
doc/python_api/examples/bpy.types.Operator.1.py
| Show All 36 Lines | def execute(self, context): | ||||
| self.report({'INFO'}, "Mouse coords are %d %d" % (self.x, self.y)) | self.report({'INFO'}, "Mouse coords are %d %d" % (self.x, self.y)) | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| def invoke(self, context, event): | def invoke(self, context, event): | ||||
| self.x = event.mouse_x | self.x = event.mouse_x | ||||
| self.y = event.mouse_y | self.y = event.mouse_y | ||||
| return self.execute(context) | return self.execute(context) | ||||
| # Only needed if you want to add into a dynamic menu | |||||
| def menu_func(self, context): | |||||
| self.layout.operator(SimpleMouseOperator.bl_idname, text="Simple Mouse Operator") | |||||
| # Register and add to the view menu (required to also use F3 search "Simple Mouse Operator" for quick access) | |||||
lichtwerk: please add the //(required to use F3 search....// part here as well | |||||
| bpy.utils.register_class(SimpleMouseOperator) | bpy.utils.register_class(SimpleMouseOperator) | ||||
| bpy.types.VIEW3D_MT_view.append(menu_func) | |||||
| # Test call to the newly defined operator. | # Test call to the newly defined operator. | ||||
| # Here we call the operator and invoke it, meaning that the settings are taken | # Here we call the operator and invoke it, meaning that the settings are taken | ||||
| # from the mouse. | # from the mouse. | ||||
| bpy.ops.wm.mouse_position('INVOKE_DEFAULT') | bpy.ops.wm.mouse_position('INVOKE_DEFAULT') | ||||
| # Another test call, this time call execute() directly with pre-defined settings. | # Another test call, this time call execute() directly with pre-defined settings. | ||||
| bpy.ops.wm.mouse_position('EXEC_DEFAULT', x=20, y=66) | bpy.ops.wm.mouse_position('EXEC_DEFAULT', x=20, y=66) | ||||
please add the (required to use F3 search.... part here as well