Post #205: joebount”:

📋 Metadata

  • Author: roaoao
  • Date: 2016-07-14 13:26:49
  • Type: answer
  • Quality Score: 9/10

🏷️ Tags

pie-menu hotkeys advanced solved

  • Pie Menu Editor
  • Stack Key Editor
  • Python Scripting
  • External Scripts

💬 Content

joebount”:

Could you tell me if it’s possible to call a context sensitive pie/menu depending on my object: a different pie/menu would open depending if I am in Object mode/Vertex mode/Edge Mode/Face mode or if nothing is selected.

So, is it possible to test the active sub-object like you did test the selected object type in your video?

Yes, it’s possible. But you need to know some python basics and Blender API.

  • First of all, create those pie menus and name them “Object mode”, “Vertex mode”, “Edge mode”, “Face mode” and “Nothing is selected”.

  • Save this script as context_sensitive_pie.py to pie_menu_editor/scripts folder:

    ao = C.active_object msm = C.tool_settings.mesh_select_mode

    def has_selection(ao, msm): import bmesh bm = bmesh.from_edit_mesh(ao.data) if msm[0]: for e in bm.verts: if e.select: return True

    if msm[1]:
        for e in bm.edges:
            if e.select:
                return True
    
    if msm[2]:
        for e in bm.faces:
            if e.select:
                return True
    
    return False
    

    if ao.mode == ‘OBJECT’: open_menu(“Object mode”)

    elif ao.mode == ‘EDIT’: if not has_selection(ao, msm): open_menu(“Nothing is selected”)

    elif msm[0]:
        open_menu("Vertex mode")
    
    elif msm[1]:
        open_menu("Edge mode")
    
    elif msm[2]:
        open_menu("Face mode")
    
  • Add a Stack Key with one command, assign Object Mode and Mesh keymaps to it and use the script as an external script in Command tab:

    execute_script(“scripts/context_sensitive_pie.py”)

  • After that you can use that stack key to open context sensitive pie menu.

FYI:


❤️ 3 likes


🔗 View on Blender Artists