I only found a similar question that does not answer mine((Python) How to add items in context menu in 2.8?).

I have this code that adds a menu to the right click context menu when you are in edit mode:

import bpy

bl_label = ''

# Leave empty for compatibility.
def draw(self, context):
pass

def draw(self, context):
layout = self.layout
layout.separator()
layout.operator('mesh.flip_normals', text = 'Flip Normals')

if __name__ == '__main__':

# Retrieve a python list for inserting draw functions.
draw_funcs.append(draw)


The problem is that the menu is added to the Vertex, Edge and Face Context Menus, but I want it only in the Face Context Menu. How can I restrict that?

• See space_view3d.py line 3807. A simple condition does the trick: if is_face_mode: ..., the flag is based on the tool settings and comes from: is_vert_mode, is_edge_mode, is_face_mode = context.tool_settings.mesh_select_mode. Aug 24 at 9:36
• @brockmann sure I've answered soemthing similar before, shrugs spent enough time looking. Aug 24 at 9:48

Use a conditional to draw.

Suggest check if the menu has a module

>>> bpy.types.VIEW3D_MT_edit_mesh_context_menu.__module__
'bl_ui.space_view3d'


and if so

>>> from bl_ui.space_view3d import VIEW3D_MT_edit_mesh_context_menu


another way check if it's registered

>>> VIEW3D_MT_edit_mesh_context_menu.is_registered
True


One of my faves is using draw_funcs. Since usage as above is the equivalent of

VIEW3D_MT_edit_mesh_context_menu.append(draw)


wouldn't bother. _or create your own class methods to manipulate the list, ie could append remove different methods in poll.

Finally to pinch @brockmann's comment above as it saves me typing same

See space_view3d.py line 3807. A simple condition does the trick: if is_face_mode: ..., the flag is based on the tool settings and comes from: is_vert_mode, is_edge_mode, is_face_mode = context.tool_settings.mesh_select_mode.