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 class VIEW3D_MT_edit_mesh_context_menu(bpy.types.Menu): 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__': # Register menu only if it doesn't already exist. rcmenu = getattr(bpy.types, "VIEW3D_MT_edit_mesh_context_menu", None) if rcmenu is None: bpy.utils.register_class(VIEW3D_MT_edit_mesh_context_menu) rcmenu = VIEW3D_MT_edit_mesh_context_menu # Retrieve a python list for inserting draw functions. draw_funcs = rcmenu._dyn_ui_initialize() 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?