1
$\begingroup$

I work as a professional Alias modeler for the automotive industry, i love Blender but after 8 hours using the same program it always take me some time to switch habits and enjoy modeling on blender.

i'm trying to step into Python to address this issue and the first thing i would like to make is a Pie Menu with similar characteristics.

Alias provide 3 pie menu, 1 for each button of the mouse and the hotkey start with SHIFT + CTRL

Anyway, i've started with a basic pie menu for vertex edge face selection that work with SHFT+CTRL+LMB the problem is when switching between selection modes it keeps the previous mode still on.

Example: Pie menu -> vertex = vertex selection active -> Pie menu -> edge = edge selection active and previous vertex selection still active.

i need a code that toggles the selection mode everytime i choose and keep a single selection mode, any help please?

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
        pie.operator_enum("mesh.select_mode", "type")


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

    wm = bpy.context.window_manager
    km = wm.keyconfigs.addon.keymaps.new(name="Mesh")
    kmi= km.keymap_items.new("wm.call_menu_pie", "LEFTMOUSE", "PRESS", shift=True, ctrl=True).properties.name="mesh.mypie"


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")
$\endgroup$
4
  • $\begingroup$ I cannot replicate the issue. Official Blender 2.83 comes with templates in the text editor and the template "UI Menu Pie" comes with selection mode menu enum pie.operator_enum("mesh.select_mode", "type") that does what you describe. Your example also seems to work for me. $\endgroup$ Jun 5, 2020 at 11:10
  • $\begingroup$ Thanks for your reply, the hotkey i want include the shift button, so every time i open my pie and select something, it consider SHIFT also as ADD to the previous selection. i need to "override" shift as ADD while i keep open my pie menu (tried with the template script aswell, same issue) that's an example of what i want to achieve: youtube.com/watch?v=y2FBoAzRMuA $\endgroup$
    – Phreno
    Jun 5, 2020 at 11:37
  • $\begingroup$ Well... I did not expect it at all, but I just tested the Text Editor's template and it seems to work with shift as well just by default. I am on Windows, Blender 2.83... $\endgroup$ Jun 5, 2020 at 11:42
  • $\begingroup$ Tried with 2.83, same issue, I've updated the first post with full code $\endgroup$
    – Phreno
    Jun 5, 2020 at 12:06

1 Answer 1

0
$\begingroup$
import bpy
from bpy.types import Menu

class VIEW3D_MT_PIE_select_mode(Menu):
    bl_label = "Select Mode"

    def draw(self, context):
        layout = self.layout
        pie = layout.menu_pie()
        o = pie.operator("mesh.select_mode", text="Vertex", icon='VERTEXSEL')
        o.type = 'VERT'
        o.use_extend=False
        o.use_expand=False
        o.action='ENABLE'
        o = pie.operator("mesh.select_mode", text="Edge", icon='EDGESEL')
        o.type = 'EDGE' 
        o.use_extend=False
        o.use_expand=False
        o.action='ENABLE'
        o = pie.operator("mesh.select_mode", text="Face", icon='FACESEL')
        o.type = 'FACE'
        o.use_extend=False
        o.use_expand=False
        o.action='ENABLE'
        o = pie.operator("mesh.select_all", text="Select All/None", icon='RESTRICT_SELECT_OFF')
        o.action = 'TOGGLE'

addon_keymaps = []

def registerKeymaps():
    wm = bpy.context.window_manager
    if wm.keyconfigs.addon:
        km = wm.keyconfigs.addon.keymaps.new(name='3D View', space_type='VIEW_3D')
        kmi = km.keymap_items.new('wm.call_menu_pie', 'LEFTMOUSE', 'CLICK_DRAG', shift=True, alt=False,ctrl=False)
        kmi.properties.name="VIEW3D_MT_PIE_select_mode"
        addon_keymaps.append((km, kmi))

def unregisterKeymaps():
    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
    addon_keymaps.clear()


def register():
    bpy.utils.register_class(VIEW3D_MT_PIE_select_mode)
    registerKeymaps()

def unregister():
    unregisterKeymaps()
    bpy.utils.unregister_class(VIEW3D_MT_PIE_select_mode)

if __name__ == "__main__":
    register()

    #bpy.ops.wm.call_menu_pie(name="VIEW3D_MT_PIE_select_mode")

This would work. But I strongly recommend not to use this since it will mess things up a lot. Shift + Left Click is used a lot in the keymap and it's not a good idea to replace it. It will make things inconsistent and I think you will likely regret it later if you get used to it doing something else in the viewport. Keys 1, 2 and 3 for mode selection are not that difficult to get used to, you should just suffer for a few days and get over it.

$\endgroup$
5
  • $\begingroup$ Thanks for your time! is a workaround but is still not working as intended and if i keep pressed shift is still multiselecting, what i'm looking is a way to disengage shift and ctrl everytime the Pie opens up, and as soon as the pie close (by release or option selected), it engage back the shift as normal, if there's no way i give up and use it as is. just trying to squeeze as much as possible the pie menu features for my needs $\endgroup$
    – Phreno
    Jun 5, 2020 at 13:07
  • $\begingroup$ OK, sorry, I misunderstood. See the updated answer. I think it makes sense to use 'CLICK_DRAG' for the shortcut so you keep add to selection functionality when selecting elements with shift left click... Just for the record, I still strongly recommend to consider getting used to 1,2,3 hotkeys instead of this. $\endgroup$ Jun 5, 2020 at 16:13
  • $\begingroup$ It doesn't work if you have all the modes enabled from the start, but seems to work if you start with one or two... It would also be possible to make your own operator to solve this if that bothers you. $\endgroup$ Jun 5, 2020 at 16:16
  • $\begingroup$ it WORK!, thanks! what was missing was CTRL also set to TRUE. Changing that it allow me to open the pie menu with 'PRESS' instead of 'CLICK_DRAG' and it retain all the functions with SHIFT without triggering the pie menu. now it work exactly like Alias, (i know it look clumsy for everybody but it have its advantage) now i will study the code to learn more and i'll expand the pie with more operations. The script is far from complete but you proved me is possible! thanks a lot for your time. $\endgroup$
    – Phreno
    Jun 5, 2020 at 17:17
  • $\begingroup$ Actually, I think it is quite convenient and makes sense on it's own, but my concern is if it works well with the rest of Blender's keymap, but I don't know - it might be OK with drag. It's just not easy to consider everything with the amount of hotkeys in all different contexts in Blender. $\endgroup$ Jun 5, 2020 at 19:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .