4
$\begingroup$

I know you can create and edit shortcuts in User Preferences > Input, but I can't figure out how to make a shortcut to toggle something on/off.

For example, I can right click on the Shade Smooth button on the Tool Shelf,
(N in the 3D view) and select "Create Shortcut" but I only can get one shortcut to shade smooth or shade flat, not one or the other based on what the current shading setting is.

So my question is,
is it possible to create a shortcut to toggle a setting?

$\endgroup$

2 Answers 2

7
$\begingroup$

That really depends on how the value is stored internally.

Blender already have operator for toggling Boolean values, like bpy.ops.wm.context_toggle. This operator alone is applicable to modify lots of properties, like active 3D view space's Only Render (space_data.show_only_render) or scene's Simplify (scene.render.use_simplify).

Some other settings may look like binary values of some property, but in fact not. Face shading is actually only accessible as two operators: faces_shade_flat and faces_shade_smooth. To toggle between both states, you'd have to write a new operator that toggles which of the two operators to execute based on another property, like a custom BoolProperty inserted to a Mesh object.

$\endgroup$
1
  • $\begingroup$ A detail, but you could toggle face smooth/flat with bpy.ops.wm.context_toggle but you would only be able to toggle a specific face index, which is- of course, not what you want. $\endgroup$
    – ideasman42
    Jul 5, 2013 at 23:08
2
$\begingroup$

To have a shortcut toggle something e.g. the flat/smooth shading, there would already have to be an operator that does that as a shortcut can only call an existing operator. So the answer is that any tool that already toggles something can have a shortcut set but anything that doesn't already toggle would have to be recoded.

For example you could write your own addon which checks the the current shading type and inverts it and then assign a shortcut for your addon.

$\endgroup$

You must log in to answer this question.

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