Getting Hotkey Commands

Thanks to Blender allowing us to see which Python commands perform which actions in Blender, it's easy to copy the code that drives a button or menu item and paste it directly into our config file to bind it to a hotkey.

Step-by-Step Examples

First, enable Python Tooltips in the Blender Preferences.

Enable Python Tooltips

Now, whenever you hover over a button or menu item, you'll get a tooltip with Python code you will be able to copy into your config file that will do exactly what that button or menu item does.

For example, this is the Python code you would copy into a hotkey eval command in your config file to add a boolean modifier:

bpy.ops.object.modifier_add(type='BOOLEAN')

And while UV editing, here's the Python code for the "Average Islands Scale" menu item:

bpy.ops.uv.average_islands_scale()

Note that both of these commands start with bpy.ops. That makes them very good candidates for Superkey hotkeys.

We're not limited to menus. Let's see a button:

bpy.ops.wm.tool_set_by_id(name="builtin_brush.Flatten")

This is the code that runs when you select the Flatten brush.

Lets try making these into a hotkey configuration:

Now, in object mode, select an object, start Superkey, and tap the b key. A Boolean Modifier is added to that object.

While UV editing, start Superkey and tap a. Average Islands Scale is automatically applied.

While sculpting, start Superkey and tap f. The Flatten brush is now selected.

Great!

Interactive Operators like Loop Cut or Bevel

If your hotkey is for an operator that's interactive, for example Loop Cut or Bevel, you'll need to add a bit more to get it to work correctly.

Using "Loop Cut and Slide" as an example (normally ctrl - r in Blender), the Python tooltip shows the operator is bpy.ops.mesh.loopcut_slide(), but if you paste this into your Superkey config it won't work because it's an operator that's interactive with your mouse.

The way to fix this is to type 'INVOKE_DEFAULT' between the parentheses, like this:

Another example is Bevel (by default ctrl - b in Blender). The Python tooltip in the menu shows the operator is bpy.ops.mesh.bevel(affect='EDGES'). In order to make this into a hotkey, you'll need to adjust it slightly to:

Changing Tool Settings

Changing tool settings often doesn't use bpy.ops operators, and instead the Python tooltips will show a bpy.data property that can be assigned a value. For these we use the exec command instead of the eval command.

Let's take changing the Dynamic Topology Refine Method as an example.

Looking at the Blender UI, the options are Subdivide Edges, Collapse Edges, and Subdivide Collapse.

The Refine Method options

If we hover over the dropdown with the mouse, we can see the underlying Python:

The Refine Method underlying Python

This doesn't give us an exact way to set this setting because it's not a bpy.ops operator and because it's dependent on the current scene named "Scene". By right-clicking the dropdown we can open the Online Python Reference:

The Online Python Reference for the Subdivide Edges option

This takes us to the documentationarrow-up-right for detail_refine_method on the sculpt mode tool settings, whose available options are:

  • SUBDIVIDE

  • COLLAPSE

  • SUBDIVIDE_COLLAPSE

At the bottom of the page, under "References", it shows that the Sculpt tool settings are referenced in ToolSettings.sculpt, which links therearrow-up-right. At the bottom of the ToolSettings page, under "References", we see that the ToolSettings are referenced by Context.tool_settings.

The chain that we just followed is hinting to us that we can set the Refine Method sculpt tool setting by using bpy.context.tool_settings.sculpt.detail_refine_method.

So let's try it.

We know we need to use the exec command and noteval because our line of Python code is assigning a value to the tool setting with the = symbol.

Now when we're in Superkey default mode, we can switch the dynamic topology refine method with the a, s, and d keys.

Following the same logic, we can even set hotkeys for changing the Dynamic Topology Detail Size:

Last updated