Blender Pie Menu help I decided to try and write an addon in Blender for a school project.
I am 100% new to the Blender api and I am trying to get my bearings from the api docs.
The below code works sometimes and most other times crashes Blender.
Anyone that can take the time to give me some pointers on what i am doing wrong here
it would be greatly appreciated
import bpy

class SCULPT_MT_pie_menu(bpy.types.Menu):
    bl_label = &quot;Pie Menu&quot;
    
    def draw(self, context):
        layout = self.layout
        layout.menu_pie().operator(&quot;sculpt.mask_brush&quot;, text = &quot;Mask Brush&quot;, icon = &quot;BLENDER&quot;)
        layout.menu_pie().operator(&quot;sculpt.remesh&quot;, text = &quot;Remesh&quot;, icon = &quot;BLENDER&quot;)

class SCULPT_OT_mask_brush(bpy.types.Operator):
    &quot;&quot;&quot;Mask Brush&quot;&quot;&quot;
    bl_idname = &quot;sculpt.mask_brush&quot;
    bl_label = &quot;Mask Brush&quot;

    def execute(self, context):
        bpy.ops.object.mode_set(mode='SCULPT')   
        bpy.ops.wm.tool_set_by_id(name=&quot;builtin_brush.Mask&quot;, cycle=False, as_fallback=False, space_type='VIEW_3D')
        return {'FINISHED'}

class SCULPT_OT_remesh(bpy.types.Operator):
    &quot;&quot;&quot;Remesh&quot;&quot;&quot;
    bl_idname = &quot;sculpt.remesh&quot;
    bl_label = &quot;Remesh&quot;

    def execute(self, context):
        bpy.ops.object.voxel_remesh()
        return {'FINISHED'}


bpy.ops.wm.call_menu_pie(name=&quot;SCULPT_MT_pie_menu&quot;)

def register():
    bpy.utils.register_class(SCULPT_MT_pie_menu)
    bpy.utils.register_class(SCULPT_OT_mask_brush)
    bpy.utils.register_class(SCULPT_OT_remesh)
  
def unregister():
    bpy.utils.unregister_class(SCULPT_MT_pie_menu)
    bpy.utils.unregister_class(SCULPT_OT_mask_brush)
    bpy.utils.unregister_class(SCULPT_OT_remesh)

if __name__ == &quot;__main__&quot;:
    register()
The way i was dealing with input was not correct i needed to use the more advanced invoke and modal options to get the desired results.
https://docs.blender.org/api/2.90/bpy.types.Operator.html?highlight=operator#module-bpy.types.Operator
Here is the updated code:
import bpy

class PS_Remesh(bpy.types.Operator):
    bl_idname = &quot;ps.remesh&quot;
    bl_label = &quot;Remesh&quot;

    def execute(self, context):
        if context.active_object is None:
            print(&quot;Active object == none: Cancel&quot;)
            return {'CANCELLED'}
        else:
            bpy.ops.object.voxel_remesh()
            return {'FINISHED'}

class PS_MaskBrush(bpy.types.Operator):
    bl_idname = &quot;ps.mask_brush&quot; #use this as the pie.operator(&quot;ps.remesh&quot;) to use in pie menu
    bl_label = &quot;Mask Brush&quot;
    
    def execute(self, context):
        if context.active_object is None:
            print(&quot;Active object == none: Cancel&quot;)
            return {'CANCELLED'}
        elif context.mode == 'SCULPT':
            print(&quot;In sculpt mode sculpt mode select mask brush&quot;)
            bpy.ops.wm.tool_set_by_id(name=&quot;builtin_brush.Mask&quot;,space_type=&quot;VIEW_3D&quot;)
            return {'FINISHED'}
        elif context.mode != 'SCULPT':
            print(&quot;Not in sculpt mode sculpt mode activate&quot;)
            bpy.ops.object.mode_set(mode='SCULPT')
            bpy.ops.wm.tool_set_by_id(name=&quot;builtin_brush.Mask&quot;, space_type=&quot;VIEW_3D&quot;)
            return {'FINISHED'}

class VIEW3D_MT_pie_sculpt(bpy.types.Menu):
    # label is displayed at the center of the pie menu.
    bl_label = &quot;Pie Sculpt&quot;

    def draw(self, context):
        pie = self.layout.menu_pie()
        pie.operator(&quot;ps.remesh&quot;, text = &quot;Remesh&quot;, icon=&quot;BLENDER&quot;)
        pie.operator(&quot;ps.mask_brush&quot;, text=&quot;Mask Brush&quot;, icon=&quot;BLENDER&quot;)


def register():
    bpy.utils.register_class(PS_Remesh)
    bpy.utils.register_class(PS_MaskBrush)
    bpy.utils.register_class(VIEW3D_MT_pie_sculpt)


def unregister():
    bpy.utils.unregister_class(PS_Remesh)
    bpy.utils.unregister_class(PS_MaskBrush)
    bpy.utils.unregister_class(VIEW3D_MT_pie_sculpt)

if __name__ == &quot;__main__&quot;:
    register()
    
    bpy.ops.wm.call_menu_pie(name=&quot;VIEW3D_MT_pie_sculpt&quot;)