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 = "Pie Menu"
def draw(self, context):
layout = self.layout
layout.menu_pie().operator("sculpt.mask_brush", text = "Mask Brush", icon = "BLENDER")
layout.menu_pie().operator("sculpt.remesh", text = "Remesh", icon = "BLENDER")
class SCULPT_OT_mask_brush(bpy.types.Operator):
"""Mask Brush"""
bl_idname = "sculpt.mask_brush"
bl_label = "Mask Brush"
def execute(self, context):
bpy.ops.object.mode_set(mode='SCULPT')
bpy.ops.wm.tool_set_by_id(name="builtin_brush.Mask", cycle=False, as_fallback=False, space_type='VIEW_3D')
return {'FINISHED'}
class SCULPT_OT_remesh(bpy.types.Operator):
"""Remesh"""
bl_idname = "sculpt.remesh"
bl_label = "Remesh"
def execute(self, context):
bpy.ops.object.voxel_remesh()
return {'FINISHED'}
bpy.ops.wm.call_menu_pie(name="SCULPT_MT_pie_menu")
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__ == "__main__":
register()