Is it possible to add a new option to the "Select Similar" (Shift+G in Edit Mode) menu of Blender?

I have a custom face data layer in my meshes to which I'd like to select all the faces with the same value in it. Out of the blue, not knowing how to approach this, I tried registering the following operator, but it did not appear:

class KclSelectSimilar(bpy.types.Operator):
    bl_idname = "mesh.select_similar_kcl_flags"
    bl_label = "Collision Flags"

    def execute(self, context):
        print("Hello World")
        return {'FINISHED'}

I thought giving it the same prefix mesh.select_similar_ like the other "Select Similar" operators would be enough.


The blender layout code can be viewed by right clicking on the select menu and selecting view source. This will open space_view3d.py in the text editor. The select similar menu can be found around line 707

class VIEW3D_MT_edit_mesh_select_similar(Menu):
    bl_label = "Select Similar"

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

        layout.operator_enum("mesh.select_similar", "type")

You can append or prepend to a menu via (see https://www.blender.org/api/current/bpy.types.Menu.html#extending-menus)

import bpy

def add_menu_item(self, context):
    self.layout.label("Added this line")


For a custom submenu, create a menu class and call layout.menu in your draw function (see Templates > Python > UI Menu template for reference):

import bpy

bl_info = {
    "name": "My Add-on",
    "description": "",
    "category": "3D View"

class VIEW3D_MT_custom_select_similar(bpy.types.Menu):
    bl_label = "Custom Menu"
    bl_idname = "VIEW3D_MT_custom_select_similar"

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

        layout.operator("wm.save_as_mainfile").copy = True


        layout.label(text="Hello world!", icon='WORLD_DATA')

        # use an operator enum property to populate a sub-menu
                                  text="Select All by Type...",

        # call another menu
        layout.operator("wm.call_menu", text="Unwrap").name = "VIEW3D_MT_uv_map"

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

def register():

    # add the menu

def unregister():

    # remove menu

if __name__ == "__main__":

enter image description here

| improve this answer | |
  • $\begingroup$ This clears a lot of things up for me! I always wondered how people found out the bpy.types enum value to add to menues. $\endgroup$ – Ray Jun 29 '16 at 10:44

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.