1
$\begingroup$

Trying to understand how i can add the operator i made to a pie menu for me to use, when i run it nothing shows. Treat me like a noob at coding, thank you for your time

import bpy
from bpy.types import Menu, Operator

# spawn an edit mode selection pie (run while object is in edit mode to get a valid output)

class hyperbevel(Operator):
    bl_idname = 'Hyper.Bevel'
    bl_label = 'HyperBevel'

    def execute(self, context):
        bpy.ops.object.editmode_toggle()
        bpy.ops.mesh.select_mode(use_extend=False,use_expand=False, type='EDGE')
        bpy.ops.mesh.select_all(action='SELECT')
        bpy.ops.mesh.mark_sharp(clear=True)
        bpy.ops.transform.edge_bevelweight(value=-1)
        bpy.ops.object.editmode_toggle()
        bpy.ops.object.transform_apply(scale=True)
        bpy.ops.object.shade_smooth()
        bpy.ops.object.modifier_remove(modifier="Bevel")
        bpy.ops.object.modifier_add(type='BEVEL')
        bpy.context.object.modifiers["Bevel"].limit_method = 'WEIGHT'
        bpy.context.object.modifiers["Bevel"].segments = 3
        bpy.ops.object.editmode_toggle()
        bpy.ops.mesh.select_all(action='DESELECT')
        bpy.ops.mesh.edges_select_sharp()
        bpy.ops.mesh.mark_sharp()
        bpy.ops.transform.edge_bevelweight(value=1)
        bpy.ops.object.editmode_toggle()
        bpy.context.object.data.use_auto_smooth = True
        bpy.context.object.modifiers["Bevel"].width = 0.02
        bpy.context.object.modifiers["Bevel"].use_clamp_overlap = False
        bpy.ops.object.modifier_move_up(modifier="Bevel")
        return ('finished')



class VIEW3D_PIE_template(Menu):
    # label is displayed at the center of the pie menu.
    bl_label = "Operators"

    def draw(self, context):
        layout = self.layout

        pie = layout.menu_pie()
        # operator_enum will just spread all available options
        # for the type enum of the operator on the pie
        pie.operator("Hyper.Bevel", text = "Hyperbevel")


def register():
    bpy.utils.register_class(VIEW3D_PIE_template)


def unregister():
    bpy.utils.unregister_class(VIEW3D_PIE_template)


if __name__ == "__main__":
    register()

    bpy.ops.wm.call_menu_pie(name="VIEW3D_PIE_template")
$\endgroup$
6
  • $\begingroup$ Copy the code and paste it in question via code $\endgroup$
    – Crantisz
    Oct 24, 2018 at 10:37
  • $\begingroup$ sorry first time posting a code, is it like this? $\endgroup$ Oct 24, 2018 at 11:21
  • $\begingroup$ there is a button code in text editor $\endgroup$
    – Crantisz
    Oct 24, 2018 at 11:23
  • $\begingroup$ ya i think i got it, not sure if people can see though $\endgroup$ Oct 24, 2018 at 11:25
  • $\begingroup$ now people can copy the code and test it $\endgroup$
    – Crantisz
    Oct 24, 2018 at 11:27

1 Answer 1

2
$\begingroup$

Register the operator class

  • Register the operator class. The bl_idname needs to be in all lower case, with one period. Blender 2.8 is a lot stricter on this and must follow the naming convention between class and operator eg OBJECT_OT_MyOperator and object.myoperator [Links]
  • The operator returns a set that contains one of ('RUNNING_MODAL', 'CANCELLED', 'FINISHED', 'PASS_THROUGH', 'INTERFACE') in this case {'FINISHED'} which is a set as indicated by the curly braces.

Amended code.

import bpy
from bpy.types import Menu, Operator

# spawn an edit mode selection pie (run while object is in edit mode to get a valid output)

class HyperBevel(Operator):
    bl_idname = "hyper.bevel"
    bl_label = "HyperBevel"

    def execute(self, context):
        bpy.ops.object.editmode_toggle()
        --- removed for brevity ---
        bpy.ops.object.modifier_move_up(modifier="Bevel")
        return {'FINISHED'}

class VIEW3D_PIE_template(Menu):
    # label is displayed at the center of the pie menu.
    bl_label = "Operators"

    def draw(self, context):
        layout = self.layout

        pie = layout.menu_pie()
        pie.operator("hyper.bevel")


def register():
    bpy.utils.register_class(VIEW3D_PIE_template)
    bpy.utils.register_class(HyperBevel)


def unregister():
    bpy.utils.unregister_class(HyperBevel)
    bpy.utils.unregister_class(VIEW3D_PIE_template)


if __name__ == "__main__":
    register()

    bpy.ops.wm.call_menu_pie(name="VIEW3D_PIE_template")
$\endgroup$
1
  • $\begingroup$ thank you so much, ya sorry i didnt know much thank you again for taking your time $\endgroup$ Oct 24, 2018 at 13:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .