I’m having a hard time trying to pass properties from the pie menu class to the operator class, moreover when this is a mouse event. I was suggested to use props, I also read on PointerProperty, not sure since I’m new to Python and the Blender API and haven’t seen something similar on other scripts.
Example test:
Summary
import bpy
from bpy.types import Menu
class COORD_MT_pie(Menu):
bl_idname = "COORD_MT_pie"
bl_label = "Mouse Coords Pie"
first_x : bpy.props.IntProperty()
first_y : bpy.props.IntProperty()
def invoke(self, context, event):
if context.space_data.type == 'VIEW_3D':
props.first_x = self.mouse_x
props.first_y = self.mouse_y
def draw(self, context):
layout = self.layout
pie = layout.menu_pie()
props = pie.operator("mouse.my_coords", text = "Coords", icon = 'OBJECT_DATA')
class Coords_OT(bpy.types.Operator):
bl_idname = "mouse.my_coords"
bl_label = "Mouse Coords"
bl_options = {'REGISTER', 'UNDO'}
# first_x : bpy.props.IntProperty()
# first_y : bpy.props.IntProperty()
@classmethod
def poll(cls, context):
mode = bpy.context.active_object.mode
return mode == 'OBJECT' or mode == 'EDIT'
def modal(self, context, event):
props.first_x = self.first_x
props.first_y = self.first_y
coord = props.first_x, props.first_y
print(coord)
return {'FINISHED'}
def invoke(self, context, event):
if context.space_data.type == 'VIEW_3D':
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
else:
self.report({'WARNING'}, "Active space must be a View3d")
return {'CANCELLED'}
def register():
bpy.utils.register_class(Coords_OT)
bpy.utils.register_class(COORD_MT_pie)
def unregister():
bpy.utils.unregister_class(Coords_OT)
bpy.utils.unregister_class(COORD_MT_pie)
if __name__ == "__main__":
register()
bpy.ops.wm.call_menu_pie(name="COORD_MT_pie")
Also I’m curious to know if there’s any UI property in the API for (Pie) button highlighting in boolean operators such as with Toggle Overlay, Toggle Xray, etc.