I am attempting to make a custom menu in Python that is context sensitive. Such that it's contents vary depending on which mode your currently in (e.g. Edit mode or Object mode).
However, when using an if and elif statement it doesn't work, and simply doesn't show those parts of the menu.
What am I doing wrong?
class QuickObjectOptions(bpy.types.Menu):
bl_idname = "object.display_options"
bl_label = "Quick Object Options"
mode = bpy.context.object.mode
def draw(self, context):
layout = self.layout
if mode == 'OBJECT':
layout.operator("object.shade_smooth", icon='SOLID')
layout.operator("object.shade_flat", icon='MESH_UVSPHERE')
elif mode == 'EDIT':
layout.operator("mesh.faces_shade_smooth", icon='SOLID')
layout.operator("mesh.faces_shade_flat", icon='MESH_UVSPHERE')
Note: I've only pasted the relavant parts of the script above to keep it simple. The "import bpy" and register functions are definitely there ;)