0
$\begingroup$

Shortcuts are cool but I believe it'd be cooler to assign multiple actions on them. Perhaps I entered the scripting area since I've seen addons that implement things I describing right now like "apply rot and scale, set origin to center of mass, selection to world origin". People are creating their own menus for that but I can clearly see how modular and customizable Blender is, so I can't say where the basic functionality ends and scripting starts.

$\endgroup$
3
  • $\begingroup$ In general it's not possible to assign a shortcut to a chain of actions, except, as you mention, by writing a python script to perform the chain and assigning the shortcut to it. $\endgroup$ Mar 22, 2022 at 20:01
  • $\begingroup$ I think bpy.types.Macro is the thing you're looking for. I have never used it but I think you'll catch a few interesting links using the keyword $\endgroup$
    – Gorgious
    Mar 22, 2022 at 20:15
  • $\begingroup$ You may consider create a operator that to execute many of operator. $\endgroup$
    – X Y
    Mar 22, 2022 at 22:33

1 Answer 1

0
$\begingroup$

This is a operator example with short cut Ctrl F9 to do Snap Cursor to Selected and Center View to Cursor

import bpy

# Snap Cursor to Selected and Center View to Cursor
class MY_OP(bpy.types.Operator):
    bl_idname = "view3d.my_operator"
    bl_label = "Operator"

    def invoke(self, context, event):
        bpy.ops.view3d.snap_cursor_to_selected('INVOKE_DEFAULT')
        bpy.ops.view3d.view_center_cursor('INVOKE_DEFAULT')
        return {'FINISHED'}


addon_keymaps = []
def register():
    bpy.utils.register_class(MY_OP)

    # Add the hotkey
    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    if kc:
        km = wm.keyconfigs.addon.keymaps.new(name='3D View', space_type='VIEW_3D')
        kmi = km.keymap_items.new("view3d.my_operator", type='F9', value='PRESS', ctrl=True)
        addon_keymaps.append((km, kmi))


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

    # Remove the hotkey
    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
    addon_keymaps.clear()

if __name__ == "__main__":
    register()

On the other hand, You can install this to addon then you not need run this script every time when blender startup.

$\endgroup$

You must log in to answer this question.

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