4
$\begingroup$

Here, I have to execute some part of coding through selecting options in Enum property.

Here is my code

class MAYA_OT_Regg(bpy.types.Operator):
 bl_idname = "maya.regging"
 bl_label = "Regging"
 bl_description = "Regging"

 def execute(self, ctx):
    return {'FINISHED'}

 def invoke(self, ctx, evt):
    return self.execute(ctx)

class MAYA_OT_Dynamic(bpy.types.Operator):
 bl_idname = "maya.dynamic"
 bl_label = "Dynamic"
 bl_description = "Dynamic"

 def execute(self, ctx):
    return {'FINISHED'}

 def invoke(self, ctx, evt):
    return self.execute(ctx)

class MENU_OT_SET(bpy.types.Menu):
 bl_label = "Menu Set"
 bl_description = "Menu set"
 def draw(self, ctx):
    ui = self.layout
    ui.operator("maya.regging")
    ui.operator("maya.dynamic")

class MAYA_OM_Panel_OP(bpy.types.Panel):
 bl_label       = "maya Tools"
 bl_space_type  = "VIEW_3D"
 bl_region_type = "TOOL_PROPS"

 def draw(self, ctx):
    ui = self.layout
    r = ui.row()
    r.menu("MENU_OT_SET", text="Menu set")
    # HERE I HAVE to COMPARE with that menu Regging and Dynamics

How to compare that Menus(Regging and Dynamics) If it's Dynamic,I have to execute some part of coding, else If it's Regging,I have to execute some part of coding.

I have searched out but none is matched with my code, so How It's possible?

$\endgroup$
  • $\begingroup$ Why not use an if statement? $\endgroup$ – gandalf3 Dec 13 '13 at 9:50
  • $\begingroup$ if ctx.mode == 'OBJECT': like this I can compare but how to compare that one....? $\endgroup$ – Rasa Mohamed Dec 13 '13 at 9:53
  • $\begingroup$ Where's the Enum property? $\endgroup$ – Adhi Dec 13 '13 at 9:54
  • $\begingroup$ sorry that is Menu now I had edited... $\endgroup$ – Rasa Mohamed Dec 13 '13 at 9:56
5
$\begingroup$

If you need user-selectable options through drop-down menu, one alternative is to use EnumProperty. For example, I use this property type to give some options to user:

widget_shape = bpy.props.EnumProperty(
    name = 'Shape',
    items = [('sphere', 'Sphere', '8x4 edges'),
             ('ring', 'Ring', '24 vertices'),
             ('square', 'Square', ''),
             ('triangle', 'Triangle', ''),
             ('bidirection', 'Bidirection', ''),
             # etc.
             ])

... that will be drawn by Blender as a drop-down menu:

1a

Upon operator invocation, I could select the function to execute based on user selection in self.widget_shape (not exactly how I did it, but basically the same):

if self.widget_shape == 'sphere':
    self.create_sphere_widget()
elif self.widget_shape == 'ring':
    self.create_ring_widget()
# etc.
$\endgroup$
  • 1
    $\begingroup$ you can pass a callback to EnumProperty(..., update=the_callback_func) to perform code when the user clicks an entry. $\endgroup$ – CodeManX Dec 13 '13 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.