2
$\begingroup$

I have these two actions

bpy.ops.object.mode_set(mode='EDIT', toggle=False)
bpy.context.tool_settings.mesh_select_mode = (True, False, False) #vertex

currently I'm running it from the text editor in blender and it works fine.

I would like to create an addon that could... run both actions (w the vertex variation) when the Key "1" is pressed, run both actions (w the edge variation) when the Key "2" is pressed, run both actions (w the face variation) when the Key "3" is pressed

So far I have this script(addon) working from the text editor, n can be installed n enabled

# by EB, done with blender 2.79
bl_info = {
    "name": "EB 3Dview >> EditMode >> VertexSelect",
    "category": "3D View",
}

import bpy


class view3dEditModeVertSel(bpy.types.Operator):
#    """Edit Mode _ Vertex Select"""      # blender will use this as a tooltip for menu items and buttons.
    bl_idname = "view3d.editmode_vertsel"        # only lowercase allowed # unique identifier for buttons and menu items to reference.
    bl_label = "view3dEditModeVertSel"         # display name in the interface.
    bl_options = {'REGISTER', 'UNDO'}  # enable undo for the operator.

    def execute(self, context):        # execute() is called by blender when running the operator.

        # The original script
        bpy.ops.object.mode_set(mode='EDIT', toggle=False)
        bpy.context.tool_settings.mesh_select_mode = (True, False, False)

        return {'FINISHED'}            # this lets blender know the operator finished successfully.

def register():
    bpy.utils.register_class(view3dEditModeVertSel)
    # bpy.ops.view3d.editmode_vertsel()

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

# This allows you to run the script directly from blenders text editor
# to test the add-on without having to install it.
if __name__ == "__main__":
    register()

Hi dr Sybren, ok I got the Addon working w hotkeys and all, I just was wondering, if is it possible to write the "Select Vertex", "Select Edge", n "Select Face" in a single addon, each one with its own hotkey, cuz I have seen that other blender py addons have multiple hotkeys assigned to them, please could you provide a code example for that?

btw would you know what is the difference between these two?

km = wm.keyconfigs.addon.keymaps.new(name='Object Mode', space_type='EMPTY')
kmi = km.keymap_items.new(view3dEditModeVertSel.bl_idname, 'SPACE', 'PRESS', ctrl=True, shift=True)
kmi.properties.total = 4
addon_keymaps.append((km, kmi))

the former is from the Blender Addon Tut, the latter from "PieMenu Addon"

km = wm.keyconfigs.addon.keymaps.new(name='Object Non-modal')
kmi = km.keymap_items.new('wm.call_menu_pie', 'Z', 'PRESS')
kmi.properties.name = "pie.shade_of"
addon_keymaps.append((km, kmi))

thanks advanced.

$\endgroup$

1 Answer 1

3
$\begingroup$

The most future-proof way to go about this is to create your own add-on. First create an operator that performs those actions. You can then bind that operator to the keyboard, add it as a button to a panel, add it to a menu, etc.

This is all documented in Blender's documentation.

$\endgroup$
10
  • $\begingroup$ Hi dr Sybren, please could you provide a code example? I'm new in programming. I had tried reading the blender addon tut before, but I just don't know what class to use for the two actions that I have in my script above. thanks advanced again $\endgroup$
    – borges
    Commented Mar 4, 2018 at 20:29
  • 1
    $\begingroup$ There are code examples in Blender's documentation. Just follow the links and read a little. $\endgroup$
    – dr. Sybren
    Commented Mar 4, 2018 at 21:02
  • $\begingroup$ I do have read it, I added the code I'm trying in my question, but it doesn't work, please could you correct it? thx advanced. $\endgroup$
    – borges
    Commented Mar 4, 2018 at 21:15
  • $\begingroup$ I can fix it, but only if you tell me what's not working, what errors you get, which version of Blender you're using, etc. $\endgroup$
    – dr. Sybren
    Commented Mar 4, 2018 at 21:26
  • 1
    $\begingroup$ Hi dr Sybren, ok I got the Addon working w hotkeys and all, I just was wondering, if is it possible to write the "Select Vertex", "Select Edge", n "Select Face" in a single addon, each one with its own hotkey, cuz I have seen that other blender py addons have multiple hotkeys assigned to them, please could you provide a code example for that? thanks advanced. $\endgroup$
    – borges
    Commented Mar 5, 2018 at 1:06

You must log in to answer this question.

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