Context sensitive pie menu

I want to add some pies that are context sensitive so when I am in face mode specific things appear

I figured that I could use this code for it

       if bpy.ops.mesh.select_mode == 'FACE'

but it does not qutie work like that. I am assuming because there are other options as well.

bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='VERT', action='TOGGLE'

How can I use this so that if the “FACE” is true then show my items, if not then dont?

Similar thing worked for me with the object mode like this

        if bpy.context.mode == 'OBJECT':
and
        if bpy.context.mode == 'EDIT_MESH':

And then just listing my operators below

check this out:

bpy.context.scene.tool_settings.mesh_select_mode[0] == 1 (for verts)

…[1] == 1 for edges
…[2] for faces

be aware that they could be verts + faces + edges at the same time, that’s why they are separated.

1 Like

Like this?

    if bpy.context.scene.tool_settings.mesh_select_mode[2] == 'True': #faces
                pie.operator("object.lasso_cut", text="Lasso Cut", icon="MOD_DASH") #Cutter 

It does not seem to work.

ok, then please provide a blend file with an executable script example so i see what you did. Because on my side this worked perfectly.

Actually I got it for the vert and the edges but the face does not work :thinking: Why is that? How do you know like why 0 == 1 is vert and 1 == 1 is edge?


import bpy
from bpy.types import Menu

# spawn an edit mode selection pie (run while object is in edit mode to get a valid output)


class VIEW3D_MT_PIE_template(Menu):
    # label is displayed at the center of the pie menu.
    bl_label = "Select Mode"

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

        pie = layout.menu_pie()
        # operator_enum will just spread all available options
        # for the type enum of the operator on the pie
        
        if bpy.context.scene.tool_settings.mesh_select_mode[0] == 1:
            
            layout.operator("mesh.primitive_uv_sphere_add", text="Vert")



        if bpy.context.scene.tool_settings.mesh_select_mode[2] == 2:
           
            layout.operator("mesh.primitive_uv_sphere_add", text="Face")

        

        if bpy.context.scene.tool_settings.mesh_select_mode[1] == 1:
            
            layout.operator("mesh.primitive_uv_sphere_add", text="Edge")
        


def register():
    bpy.utils.register_class(VIEW3D_MT_PIE_template)


def unregister():
    bpy.utils.unregister_class(VIEW3D_MT_PIE_template)


if __name__ == "__main__":
    register()

    bpy.ops.wm.call_menu_pie(name="VIEW3D_MT_PIE_template")

I think I figured but the only issue I have with this is that when I go fo object mode. I still get the options that were shown for last used selection mode. So If I had edges selected when I exit I still get the message “Edgeeee”. Is there any way to hide that? My object mode code is this

    if bpy.context.mode == 'OBJECT':

And I also use this generic

    if bpy.context.mode == 'EDIT MESH':
import bpy
from bpy.types import Menu

# spawn an edit mode selection pie (run while object is in edit mode to get a valid output)


class VIEW3D_MT_PIE_template(Menu):
    # label is displayed at the center of the pie menu.
    bl_label = "Select Mode"

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

        pie = layout.menu_pie()
        # operator_enum will just spread all available options
        # for the type enum of the operator on the pie
        
        if bpy.context.scene.tool_settings.mesh_select_mode[0] == True:
            
            layout.operator("mesh.primitive_uv_sphere_add", text="Vert")

        if bpy.context.scene.tool_settings.mesh_select_mode[1] == True:
            
            layout.operator("mesh.primitive_uv_sphere_add", text="                       Edgeeeeeeeeeeeeeeee")



        if bpy.context.scene.tool_settings.mesh_select_mode[2] == True:
           
            layout.operator("mesh.primitive_uv_sphere_add", text="                  ffffffffffffFace")

        


        


def register():
    bpy.utils.register_class(VIEW3D_MT_PIE_template)


def unregister():
    bpy.utils.unregister_class(VIEW3D_MT_PIE_template)


if __name__ == "__main__":
    register()

    bpy.op

s.wm.call_menu_pie(name=“VIEW3D_MT_PIE_template”)